# Model picker

> Compact pill model selector with provider filter tabs, context window and token pricing details, and reasoning-effort controls.

- Kind: block · Category: AI · Interactivity: script
- Install: `npx shadcn@latest add @haze/model-picker`
- File: `src/components/haze/blocks/model-picker.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/model-picker

## Use when
- Letting users pick between multiple LLM providers with context length and pricing visible
- Pairing model selection with a reasoning-effort toggle in a compact panel

## Avoid when
- You only have two or three plain options with no metadata; use select or morph-select

## Alternatives
- [morph-select](https://hazeui.com/ui/morph-select.md)
- [dropdown-menu](https://hazeui.com/ui/dropdown-menu.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-model-picker" | no | Unique prefix for panel and aria-controls links. |
| heading | `string` | "Choose a model" | no | Label shown beside the pill trigger. |
| models | `ModelOption[]` | 5 demo models | no | Models with provider, summary, context window and token price. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- The trigger pill communicates panel visibility with aria-expanded and aria-controls.
- Model choices and reasoning-effort buttons expose aria-pressed and announce updates in a live status region.
- Key Tab: Move between the trigger pill, provider tabs, model rows and effort buttons
- Key Enter / Space: Open or close the picker, switch provider tabs, or select a model and effort level

## Agent prompts

### Install and use

Install the Haze UI block "Model picker" with `npx shadcn@latest add @haze/model-picker`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ModelPicker from "@/components/haze/blocks/model-picker.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/model-picker.md

### Customize with real content

Adapt the Haze model-picker block for our product. Replace the demo values of these props with our real content: id, heading, models, class. Keep the layout, the heading level rules and these accessibility details: The trigger pill communicates panel visibility with aria-expanded and aria-controls. Model choices and reasoning-effort buttons expose aria-pressed and announce updates in a live status region. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using model-picker, check it fits: use it when letting users pick between multiple llm providers with context length and pricing visible; pairing model selection with a reasoning-effort toggle in a compact panel. Avoid it when you only have two or three plain options with no metadata; use select or morph-select. Alternatives: @haze/morph-select, @haze/dropdown-menu.

## Example requests that should lead here
- Create a model picker pill that opens a panel with featured models, provider tabs, token pricing and reasoning effort

## Source

```astro
---
import { Check, ChevronDown, Cpu, Gauge } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface ModelOption {
  id: string;
  name: string;
  provider: "Anthropic" | "Google" | "OpenAI";
  summary: string;
  context: string;
  price: string;
  featured?: boolean;
}

interface Props {
  id?: string;
  heading?: string;
  models?: ModelOption[];
  class?: string;
}

const {
  id = "haze-model-picker",
  heading = "Choose a model",
  models = [
    { id: "sonnet-45", name: "Sonnet 4.5", provider: "Anthropic", summary: "Balanced coding, analysis and structured edits", context: "200k ctx", price: "$3 / 1M", featured: true },
    { id: "gemini-pro", name: "Gemini 3.8 Pro", provider: "Google", summary: "Long-context reasoning across repositories and docs", context: "1M ctx", price: "$2.50 / 1M", featured: true },
    { id: "gpt-5", name: "GPT-5 Mini", provider: "OpenAI", summary: "Fast everyday tasks with low first-token latency", context: "128k ctx", price: "$0.60 / 1M", featured: true },
    { id: "opus-45", name: "Opus 4.5", provider: "Anthropic", summary: "Deep architecture and multi-step planning", context: "200k ctx", price: "$15 / 1M" },
    { id: "gemini-flash", name: "Gemini 3.8 Flash", provider: "Google", summary: "High-throughput extraction and classification", context: "1M ctx", price: "$0.25 / 1M" },
  ],
  class: className,
} = Astro.props;
const firstModel = models[0];
const providers = ["Featured", "Anthropic", "Google", "OpenAI"] as const;
---

<section aria-labelledby={`${id}-title`} data-haze-model-picker class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-md space-y-3">
    <div class="flex items-center justify-between gap-2">
      <h2 id={`${id}-title`} class="text-sm/5 font-semibold text-foreground">{heading}</h2>
      <button
        type="button"
        data-mp-trigger
        hidden={!firstModel}
        aria-expanded="true"
        aria-controls={`${id}-panel`}
        class="inline-flex h-9 cursor-pointer items-center gap-2 rounded-full border border-frame-strong bg-field px-3.5 text-xs font-medium text-foreground shadow-key transition-colors duration-150 hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
      >
        <Cpu class="size-3.5 text-muted-foreground" aria-hidden="true" />
        <span data-mp-current>{firstModel?.name}</span>
        <span data-mp-effort-badge class="rounded-sm bg-muted px-1.5 py-0.5 text-[0.6875rem] text-muted-foreground">Medium</span>
        <ChevronDown class="size-3.5 text-muted-foreground" aria-hidden="true" />
      </button>
    </div>

    {!firstModel && <p class="text-sm/6 text-muted-foreground">No models are available.</p>}
    <div id={`${id}-panel`} data-mp-panel hidden={!firstModel} class="rounded-2xl border border-border bg-popover p-3 shadow-float">
      <div role="tablist" aria-label="Filter models by provider" class="flex flex-wrap gap-1 border-b border-border pb-2.5">
        {
          providers.map((prov, idx) => (
            <button
              type="button"
              role="tab"
              data-mp-tab={prov}
              aria-selected={idx === 0 ? "true" : "false"}
              class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:text-foreground aria-selected:bg-accent aria-selected:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
            >
              {prov}
            </button>
          ))
        }
      </div>

      <ul role="list" class="mt-2.5 grid gap-1">
        {
          models.map((m, idx) => (
            <li data-mp-item data-provider={m.provider} data-featured={m.featured ? "true" : "false"} hidden={!m.featured}>
              <button
                type="button"
                data-mp-pick={m.id}
                data-mp-name={m.name}
                aria-pressed={idx === 0 ? "true" : "false"}
                class="group flex w-full cursor-pointer items-start justify-between gap-3 rounded-xl border border-transparent p-2.5 text-left transition-colors duration-150 hover:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring aria-pressed:border-border-strong aria-pressed:bg-card active:scale-[0.97] active:duration-75"
              >
                <div class="min-w-0">
                  <div class="flex items-center gap-2">
                    <span class="text-sm/5 font-medium text-foreground">{m.name}</span>
                    <span class="text-[0.6875rem]/4 text-muted-foreground">{m.provider}</span>
                  </div>
                  <p class="mt-0.5 text-xs/5 text-muted-foreground">{m.summary}</p>
                  <p class="mt-1 flex items-center gap-2 font-mono text-[0.6875rem]/4 text-muted-foreground tabular-nums">
                    <span>{m.context}</span>
                    <span aria-hidden="true">·</span>
                    <span>{m.price}</span>
                  </p>
                </div>
                <Check class="mt-0.5 size-4 shrink-0 text-foreground opacity-0 group-aria-pressed:opacity-100" aria-hidden="true" />
              </button>
            </li>
          ))
        }
      </ul>

      <div class="mt-3 flex items-center justify-between gap-3 border-t border-border pt-3">
        <span class="inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
          <Gauge class="size-3.5" aria-hidden="true" />
          Reasoning effort
        </span>
        <div role="group" aria-label="Reasoning effort" class="inline-flex rounded-lg border border-frame bg-muted p-0.5">
          {
            ["Low", "Medium", "High"].map((lvl) => (
              <button
                type="button"
                data-mp-effort={lvl}
                aria-pressed={lvl === "Medium" ? "true" : "false"}
                class="relative inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:text-foreground aria-pressed:bg-card aria-pressed:text-foreground aria-pressed:shadow-key focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
              >
                {lvl}
              </button>
            ))
          }
        </div>
      </div>
    </div>

    <p data-mp-status role="status" class="min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initModelPickers() {
    document.querySelectorAll<HTMLElement>("[data-haze-model-picker]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const trigger = root.querySelector<HTMLButtonElement>("[data-mp-trigger]");
      const panel = root.querySelector<HTMLElement>("[data-mp-panel]");
      const current = root.querySelector<HTMLElement>("[data-mp-current]");
      const effortBadge = root.querySelector<HTMLElement>("[data-mp-effort-badge]");
      const status = root.querySelector<HTMLElement>("[data-mp-status]");

      trigger?.addEventListener("click", () => {
        if (!panel) return;
        panel.hidden = !panel.hidden;
        trigger.setAttribute("aria-expanded", String(!panel.hidden));
      });

      root.querySelectorAll<HTMLButtonElement>("[data-mp-tab]").forEach((tab) => {
        tab.addEventListener("click", () => {
          const prov = tab.dataset.mpTab!;
          root.querySelectorAll<HTMLButtonElement>("[data-mp-tab]").forEach((t) => t.setAttribute("aria-selected", String(t === tab)));
          root.querySelectorAll<HTMLElement>("[data-mp-item]").forEach((item) => {
            item.hidden = prov === "Featured" ? item.dataset.featured !== "true" : item.dataset.provider !== prov;
          });
        });
      });

      root.querySelectorAll<HTMLButtonElement>("[data-mp-pick]").forEach((btn) => {
        btn.addEventListener("click", () => {
          root.querySelectorAll<HTMLButtonElement>("[data-mp-pick]").forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
          const name = btn.dataset.mpName ?? "";
          if (current) current.textContent = name;
          if (status) status.textContent = `Selected ${name}.`;
        });
      });

      root.querySelectorAll<HTMLButtonElement>("[data-mp-effort]").forEach((btn) => {
        btn.addEventListener("click", () => {
          const lvl = btn.dataset.mpEffort ?? "Medium";
          root.querySelectorAll<HTMLButtonElement>("[data-mp-effort]").forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
          if (effortBadge) effortBadge.textContent = lvl;
          if (status) status.textContent = `Reasoning effort set to ${lvl}.`;
        });
      });
    });
  }
  initModelPickers();
  document.addEventListener("astro:page-load", initModelPickers);
</script>
```
