Skip to content
2k
On This Page

Model Selector

Two menus. One picks the model the agent runs, the other picks how hard it thinks.

// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { For, createSignal } from "solid-js"

import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger
} from "~/components/ui/dropdown-menu"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupTextarea
} from "~/components/ui/input-group"

const providers = [
  {
    name: "OpenAI",
    models: [
      { id: "gpt-5", name: "GPT-5" },
      { id: "gpt-5-mini", name: "GPT-5 mini" }
    ]
  },
  {
    name: "Anthropic",
    models: [
      { id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },
      { id: "claude-haiku-4-5", name: "Claude Haiku 4.5" }
    ]
  }
]

const models = providers.flatMap((provider) => provider.models)

const efforts = [
  { id: "low", name: "Low" },
  { id: "medium", name: "Medium" },
  { id: "high", name: "High" }
]

export default function ModelSelectorDemo() {
  const [text, setText] = createSignal("")
  const [model, setModel] = createSignal(models[0]!.id)
  const [effort, setEffort] = createSignal(efforts[1]!.id)
  let formRef: HTMLFormElement | undefined
  const currentModel = () =>
    models.find((item) => item.id === model()) ?? models[0]!
  const currentEffort = () =>
    efforts.find((item) => item.id === effort()) ?? efforts[1]!
  const canSend = () => text().trim().length > 0

  function onSubmit(event: SubmitEvent & { currentTarget: HTMLFormElement }) {
    event.preventDefault()
    if (!canSend()) {
      return
    }

    setText("")
  }

  return (
    <div class="mx-auto w-full max-w-lg py-6">
      <form
        ref={(element) => {
          formRef = element
        }}
        onSubmit={onSubmit}
      >
        <InputGroup>
          <InputGroupTextarea
            value={text()}
            onInput={(event) => setText(event.currentTarget.value)}
            placeholder="Ask the agent to change your code..."
            onKeyDown={(event) => {
              if (event.key === "Enter" && !event.shiftKey) {
                event.preventDefault()
                formRef?.requestSubmit()
              }
            }}
            class="p-3"
          />
          <InputGroupAddon align="block-end">
            <InputGroupButton
              type="submit"
              size="icon-sm"
              variant="outline"
              class="rounded-full"
              disabled={canSend()}
              aria-label="Attach"
            >
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <path d="M5 12h14" />
                <path d="M12 5v14" />
              </svg>
            </InputGroupButton>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={(triggerProps) => (
                  <InputGroupButton
                    {...triggerProps}
                    size="sm"
                    variant="outline"
                    aria-label={`Model: ${currentModel().name}`}
                    class="ml-auto"
                  >
                    {currentModel().name}
                    <svg
                      width="24"
                      height="24"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="2"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      aria-hidden="true"
                    >
                      <path d="m6 9 6 6 6-6" />
                    </svg>
                  </InputGroupButton>
                )}
              />
              <DropdownMenuContent align="start" class="w-48">
                <DropdownMenuRadioGroup
                  value={model()}
                  onValueChange={setModel}
                >
                  {
                    <For each={providers}>
                      {(provider, index) => (
                        <>
                          {index() > 0 && <DropdownMenuSeparator />}
                          <DropdownMenuGroup>
                            <DropdownMenuLabel>
                              {provider.name}
                            </DropdownMenuLabel>
                            {
                              <For each={provider.models}>
                                {(item) => (
                                  <DropdownMenuRadioItem value={item.id}>
                                    {item.name}
                                  </DropdownMenuRadioItem>
                                )}
                              </For>
                            }
                          </DropdownMenuGroup>
                        </>
                      )}
                    </For>
                  }
                </DropdownMenuRadioGroup>
              </DropdownMenuContent>
            </DropdownMenu>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={(triggerProps) => (
                  <InputGroupButton
                    {...triggerProps}
                    size="sm"
                    variant="outline"
                    aria-label={`Effort: ${currentEffort().name}`}
                  >
                    <span class="text-muted-foreground">Effort</span>
                    {currentEffort().name}
                    <svg
                      width="24"
                      height="24"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="2"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      aria-hidden="true"
                    >
                      <path d="m6 9 6 6 6-6" />
                    </svg>
                  </InputGroupButton>
                )}
              />
              <DropdownMenuContent align="start" class="w-36">
                <DropdownMenuGroup>
                  <DropdownMenuLabel>Effort</DropdownMenuLabel>
                  <DropdownMenuRadioGroup
                    value={effort()}
                    onValueChange={setEffort}
                  >
                    {
                      <For each={efforts}>
                        {(item) => (
                          <DropdownMenuRadioItem value={item.id}>
                            {item.name}
                          </DropdownMenuRadioItem>
                        )}
                      </For>
                    }
                  </DropdownMenuRadioGroup>
                </DropdownMenuGroup>
              </DropdownMenuContent>
            </DropdownMenu>
            <InputGroupButton
              type="submit"
              size="icon-sm"
              variant="default"
              class="rounded-full"
              disabled={!canSend()}
              aria-label="Send"
            >
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <path d="m5 12 7-7 7 7" />
                <path d="M12 19V5" />
              </svg>
            </InputGroupButton>
          </InputGroupAddon>
        </InputGroup>
      </form>
    </div>
  )
}

Installation

Model Selector is built with the Dropdown Menu and Input Group components.

pnpm dlx solidui-cli@latest add dropdown-menu input-group

Install the required Solid UI dependencies:

pnpm dlx solidui-cli@latest add dropdown-menu input-group

Copy and paste the following code into your project.

components/ui/dropdown-menu.tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import { type ComponentProps } from "@solidjs/web"
import {
  Menu as SdkMenu,
  MenuTrigger as SdkMenuTrigger,
  MenuContent as SdkMenuContent,
  MenuGroup as SdkMenuGroup,
  MenuGroupLabel as SdkMenuGroupLabel,
  MenuItem as SdkMenuItem,
  MenuSub as SdkMenuSub,
  MenuSubTrigger as SdkMenuSubTrigger,
  MenuSubContent as SdkMenuSubContent,
  MenuCheckboxItem as SdkMenuCheckboxItem,
  MenuItemIndicator as SdkMenuItemIndicator,
  MenuRadioGroup as SdkMenuRadioGroup,
  MenuRadioItem as SdkMenuRadioItem,
  MenuSeparator as SdkMenuSeparator
} from "@ui-sdk/solid/menu"
import { createUniqueId, merge, omit } from "solid-js"

import { cn } from "~/lib/utils"
type DropdownMenuProps = ComponentProps<typeof SdkMenu>
const DropdownMenu = (props: DropdownMenuProps) => <SdkMenu {...props} />
type DropdownMenuTriggerProps = Omit<
  ComponentProps<typeof SdkMenuTrigger>,
  "class"
> & {
  class?: string
}
const DropdownMenuTrigger = (props: DropdownMenuTriggerProps) => (
  <SdkMenuTrigger {...props} class={props.class} />
)
type DropdownMenuContentProps = Omit<
  ComponentProps<typeof SdkMenuContent>,
  "class"
> & {
  class?: string
}
const DropdownMenuContent = (props: DropdownMenuContentProps) => (
  <>
    <SdkMenuContent
      {...props}
      class={cn(
        "min-w-32 rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-ending-style:animate-out data-ending-style:fade-out-0 data-ending-style:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 z-50 max-h-(--available-height) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden",
        props.class
      )}
    />
  </>
)
type DropdownMenuGroupProps = Omit<
  ComponentProps<typeof SdkMenuGroup>,
  "class"
> & {
  class?: string
}
const DropdownMenuGroup = (props: DropdownMenuGroupProps) => (
  <SdkMenuGroup {...props} class={props.class} />
)
type DropdownMenuLabelProps = (Omit<
  ComponentProps<typeof SdkMenuGroupLabel>,
  "class"
> & {
  class?: string
}) & {
  inset?: boolean
}
const DropdownMenuLabel = (props: DropdownMenuLabelProps) => {
  const others = omit(props, "class", "inset")
  return (
    <SdkMenuGroupLabel
      data-inset={props.inset}
      class={cn("px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7 data-inset:pl-8", props.class)}
      {...others}
    />
  )
}
type DropdownMenuItemProps = (Omit<
  ComponentProps<typeof SdkMenuItem>,
  "class"
> & {
  class?: string
}) & {
  inset?: boolean
  variant?: "default" | "destructive"
}
const DropdownMenuItem = (rawProps: DropdownMenuItemProps) => {
  const local = merge(
    { variant: "default" } as DropdownMenuItemProps,
    rawProps
  ) as DropdownMenuItemProps
  const others = omit(rawProps, "class", "inset", "variant")
  return (
    <SdkMenuItem
      data-inset={local.inset}
      data-variant={local.variant}
      class={cn(
        "gap-1.5 rounded-md px-1.5 py-1 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
        local.class
      )}
      {...others}
    />
  )
}
type DropdownMenuSubProps = ComponentProps<typeof SdkMenuSub>
const DropdownMenuSub = (props: DropdownMenuSubProps) => (
  <SdkMenuSub {...props} />
)
type DropdownMenuSubTriggerProps = (Omit<
  ComponentProps<typeof SdkMenuSubTrigger>,
  "class"
> & {
  class?: string
}) & {
  inset?: boolean
}
const DropdownMenuSubTrigger = (props: DropdownMenuSubTriggerProps) => {
  const others = omit(props, "class", "inset", "children")
  return (
    <SdkMenuSubTrigger
      data-inset={props.inset}
      class={cn(
        "gap-1.5 rounded-md px-1.5 py-1 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg:not([class*='size-'])]:size-4 flex cursor-default items-center outline-hidden select-none data-inset:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0",
        props.class
      )}
      {...others}
    >
      {props.children}
      <svg
        width="24"
        height="24"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
        class="ml-auto"
      >
        <path d="m9 18 6-6-6-6" />
      </svg>
    </SdkMenuSubTrigger>
  )
}
type DropdownMenuSubContentProps = Omit<
  ComponentProps<typeof SdkMenuSubContent>,
  "class"
> & {
  class?: string
}
const DropdownMenuSubContent = (props: DropdownMenuSubContentProps) => (
  <>
    <SdkMenuSubContent
      {...props}
      class={cn(
        "min-w-[96px] rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-ending-style:animate-out data-ending-style:fade-out-0 data-ending-style:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 z-50 max-h-(--available-height) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden",
        props.class
      )}
    />
  </>
)
type DropdownMenuCheckboxItemProps = Omit<
  Omit<ComponentProps<typeof SdkMenuCheckboxItem>, "value"> & {
    value?: string
  },
  "class"
> & {
  class?: string
}
const DropdownMenuCheckboxItem = (props: DropdownMenuCheckboxItemProps) => {
  const others = omit(props, "class", "children", "value")
  const value = createUniqueId()
  return (
    <SdkMenuCheckboxItem
      value={props.value ?? value}
      class={cn(
        "gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
        props.class
      )}
      {...others}
    >
      <span class="absolute right-2 flex items-center justify-center pointer-events-none">
        <SdkMenuItemIndicator>
          <svg
            width="24"
            height="24"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M20 6 9 17l-5-5" />
          </svg>
        </SdkMenuItemIndicator>
      </span>
      {props.children}
    </SdkMenuCheckboxItem>
  )
}
type DropdownMenuRadioGroupProps = Omit<
  ComponentProps<typeof SdkMenuRadioGroup>,
  "class"
> & {
  class?: string
}
const DropdownMenuRadioGroup = (props: DropdownMenuRadioGroupProps) => (
  <SdkMenuRadioGroup {...props} class={props.class} />
)
type DropdownMenuRadioItemProps = Omit<
  ComponentProps<typeof SdkMenuRadioItem>,
  "class"
> & {
  class?: string
}
const DropdownMenuRadioItem = (props: DropdownMenuRadioItemProps) => {
  const others = omit(props, "class", "children")
  return (
    <SdkMenuRadioItem
      class={cn(
        "gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
        props.class
      )}
      {...others}
    >
      <span class="absolute right-2 flex items-center justify-center pointer-events-none">
        <SdkMenuItemIndicator>
          <svg
            width="24"
            height="24"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M20 6 9 17l-5-5" />
          </svg>
        </SdkMenuItemIndicator>
      </span>
      {props.children}
    </SdkMenuRadioItem>
  )
}
type DropdownMenuSeparatorProps = Omit<
  ComponentProps<typeof SdkMenuSeparator>,
  "class"
> & {
  class?: string
}
const DropdownMenuSeparator = (props: DropdownMenuSeparatorProps) => (
  <SdkMenuSeparator
    {...props}
    class={cn("-mx-1 my-1 h-px bg-border", props.class)}
  />
)
type DropdownMenuShortcutProps = ComponentProps<"span">
const DropdownMenuShortcut = (props: DropdownMenuShortcutProps) => (
  <span {...props} class={cn("ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground", props.class)} />
)
export {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger
}

Update the import paths to match your project setup.

Usage

import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuTrigger
} from "~/components/ui/dropdown-menu"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupButton,
  InputGroupTextarea
} from "~/components/ui/input-group"
<InputGroup>
  <InputGroupTextarea placeholder="Ask the agent to change your code..." />
  <InputGroupAddon align="block-end">
    <DropdownMenu>
      <DropdownMenuTrigger
        render={(triggerProps) => (
          <InputGroupButton {...triggerProps} size="sm">
            GPT-5
            <ChevronDownIcon />
          </InputGroupButton>
        )}
      />
      <DropdownMenuContent align="start">
        <DropdownMenuRadioGroup value={model} onValueChange={setModel}>
          <DropdownMenuGroup>
            <DropdownMenuLabel>OpenAI</DropdownMenuLabel>
            <DropdownMenuRadioItem value="gpt-5">GPT-5</DropdownMenuRadioItem>
            <DropdownMenuRadioItem value="gpt-5-mini">
              GPT-5 mini
            </DropdownMenuRadioItem>
          </DropdownMenuGroup>
        </DropdownMenuRadioGroup>
      </DropdownMenuContent>
    </DropdownMenu>
    <DropdownMenu>
      <DropdownMenuTrigger
        render={(triggerProps) => (
          <InputGroupButton {...triggerProps} size="sm">
            Medium
            <ChevronDownIcon />
          </InputGroupButton>
        )}
      />
      <DropdownMenuContent align="start">
        <DropdownMenuRadioGroup value={effort} onValueChange={setEffort}>
          <DropdownMenuRadioItem value="low">Low</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="medium">Medium</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="high">High</DropdownMenuRadioItem>
        </DropdownMenuRadioGroup>
      </DropdownMenuContent>
    </DropdownMenu>
    <InputGroupButton type="submit" variant="default" class="ml-auto">
      <ArrowUpIcon />
    </InputGroupButton>
  </InputGroupAddon>
</InputGroup>

AI SDK

Send the model and the effort with the message. Map them to a model and provider options in the route.

sendMessage({ text }, { body: { model, effort } })
app/api/chat/route.ts
import { anthropic } from "@ai-sdk/anthropic"
import { openai } from "@ai-sdk/openai"
import { convertToModelMessages, streamText, type UIMessage } from "ai"
 
const models = {
  "gpt-5": openai("gpt-5"),
  "gpt-5-mini": openai("gpt-5-mini"),
  "claude-sonnet-4-5": anthropic("claude-sonnet-4-5"),
  "claude-haiku-4-5": anthropic("claude-haiku-4-5")
}
 
export async function POST(req: Request) {
  const { messages, model, effort } = (await req.json()) as {
    messages: UIMessage[]
    model: keyof typeof models
    effort: "low" | "medium" | "high"
  }
 
  const result = streamText({
    model: models[model] ?? models["gpt-5"],
    messages: await convertToModelMessages(messages),
    providerOptions: {
      openai: { reasoningEffort: effort },
      anthropic: { effort }
    }
  })
 
  return result.toUIMessageStreamResponse()
}

Each provider reads its own key in providerOptions and ignores the rest.

Migrating from AI SDK Elements

If you added Model Selector from AI SDK Elements, your project has a components/ai-elements/model-selector.tsx wrapper. Paste this prompt into your coding agent to rebuild it on Dropdown Menu. Every export keeps its name and props, so the code that uses it keeps working.

Prompt
Migrate components/ai-elements/model-selector.tsx from AI SDK Elements to the Solid UI Dropdown Menu component.
 
Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.
 
1. Install Dropdown Menu: npx solidui-cli@latest add dropdown-menu
2. Read https://www.solid-ui.com/docs/ai-elements/model-selector.md and build Model Selector the same way.
3. Rebuild each part:
   - ModelSelector renders a DropdownMenu, instead of a Dialog. ModelSelectorTrigger renders a DropdownMenuTrigger with render.
   - ModelSelectorContent renders a DropdownMenuContent, and ModelSelectorList a DropdownMenuRadioGroup with the selected model as its value.
   - ModelSelectorGroup renders a DropdownMenuGroup with a DropdownMenuLabel for its heading.
   - ModelSelectorItem renders a DropdownMenuRadioItem. Picking a model closes the menu.
   - ModelSelectorSeparator renders a DropdownMenuSeparator, and ModelSelectorShortcut a DropdownMenuShortcut.
   - A menu has no search field. Keep ModelSelectorInput, ModelSelectorEmpty and ModelSelectorDialog on Command if you use search, or remove them if nothing imports them.
   - Keep ModelSelectorLogo, ModelSelectorLogoGroup and ModelSelectorName as they are.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.