Back to Copilotkit

Model Selection

showcase/shell-docs/src/content/docs/integrations/built-in-agent/model-selection.mdx

1.60.15.4 KB
Original Source

The Built-in Agent uses the Vercel AI SDK, so you can use models from OpenAI, Anthropic, and Google, or pass any custom AI SDK model.

Supported Models

Specify a model using the "provider:model" format. "provider/model" also works.

OpenAI

ModelSpecifier
GPT-5openai:gpt-5
GPT-5 Miniopenai:gpt-5-mini
GPT-4.1openai:gpt-4.1
GPT-4.1 Miniopenai:gpt-4.1-mini
GPT-4.1 Nanoopenai:gpt-4.1-nano
GPT-4oopenai:gpt-4o
GPT-4o Miniopenai:gpt-4o-mini
o3openai:o3
o3-miniopenai:o3-mini
o4-miniopenai:o4-mini
typescript
const agent = new BuiltInAgent({
  model: "openai:gpt-4.1",
});

Anthropic

ModelSpecifier
Claude Sonnet 4.5anthropic:claude-sonnet-4.5
Claude Sonnet 4anthropic:claude-sonnet-4
Claude 3.7 Sonnetanthropic:claude-3.7-sonnet
Claude Opus 4.1anthropic:claude-opus-4.1
Claude Opus 4anthropic:claude-opus-4
Claude 3.5 Haikuanthropic:claude-3.5-haiku
typescript
const agent = new BuiltInAgent({
  model: "anthropic:claude-sonnet-4.5",
});

Google

ModelSpecifier
Gemini 2.5 Progoogle:gemini-2.5-pro
Gemini 2.5 Flashgoogle:gemini-2.5-flash
Gemini 2.5 Flash Litegoogle:gemini-2.5-flash-lite
typescript
const agent = new BuiltInAgent({
  model: "google:gemini-2.5-pro",
});

Environment Variables

Set the API key for your chosen provider:

bash
# OpenAI
OPENAI_API_KEY=sk-...

# Anthropic
ANTHROPIC_API_KEY=sk-ant-...

# Google
GOOGLE_API_KEY=...

Alternatively, pass the API key directly in your configuration:

typescript
const agent = new BuiltInAgent({
  model: "openai:gpt-4.1",
  apiKey: process.env.MY_OPENAI_KEY, // [!code highlight]
});

Custom Models (AI SDK)

For models not in the built-in list, you can pass any Vercel AI SDK LanguageModel instance directly:

typescript
import { BuiltInAgent } from "@copilotkit/runtime/v2";
import { createOpenAI } from "@ai-sdk/openai"; // [!code highlight]

const customProvider = createOpenAI({ // [!code highlight]
  apiKey: process.env.MY_API_KEY, // [!code highlight]
  baseURL: "https://my-proxy.example.com/v1", // [!code highlight]
}); // [!code highlight]

const agent = new BuiltInAgent({
  model: customProvider("my-fine-tuned-model"), // [!code highlight]
});

This works with any AI SDK provider, including Azure OpenAI, AWS Bedrock, Ollama, or any OpenAI-compatible endpoint:

typescript
import { createAzure } from "@ai-sdk/azure";

const azure = createAzure({
  resourceName: "my-resource",
  apiKey: process.env.AZURE_API_KEY,
});

const agent = new BuiltInAgent({
  model: azure("my-deployment"),
});

OpenRouter, proxies, and bring-your-own LLM

Anything that exposes an OpenAI-compatible API, including OpenRouter, a self-hosted gateway, an internal LLM proxy, Ollama, Together, Groq, or your own fine-tuned endpoint, works through the same createOpenAI({ baseURL }) pattern shown in Custom Models above. Point baseURL at the provider's OpenAI-compatible route and pass your key:

typescript
import { BuiltInAgent } from "@copilotkit/runtime/v2";
import { createOpenAI } from "@ai-sdk/openai"; // [!code highlight]

// OpenRouter: one key, hundreds of models behind an OpenAI-compatible API
const openrouter = createOpenAI({ // [!code highlight]
  apiKey: process.env.OPENROUTER_API_KEY, // [!code highlight]
  baseURL: "https://openrouter.ai/api/v1", // [!code highlight]
}); // [!code highlight]

const agent = new BuiltInAgent({
  model: openrouter("anthropic/claude-sonnet-4.5"), // [!code highlight]
});

The same shape works for any OpenAI-compatible proxy. Swap the baseURL and key. There is no CopilotKit-specific provider to install; if the AI SDK can talk to it, the Built-in Agent can use it.

<Callout type="warn" title="The model is set on the agent"> CopilotKit does **not** expose a hosted/Cloud endpoint for choosing or switching the model at request time. The model is configured **on the agent**, either as a `"provider:model"` string or an AI SDK `LanguageModel` instance:
typescript
new BuiltInAgent({ model: "openai:gpt-4.1" });        // built-in string
new BuiltInAgent({ model: openrouter("...") });        // any LanguageModel

To switch models per user, request, or feature flag, construct the agent with the desired model on your own backend. For full control over the runtime you can also use a Custom Agent. </Callout>

How it works

The Built-in Agent resolves model strings to AI SDK provider instances:

Model stringAI SDK providerResolved call
"openai:gpt-4.1"@ai-sdk/openaiopenai("gpt-4.1")
"anthropic:claude-sonnet-4.5"@ai-sdk/anthropicanthropic("claude-sonnet-4.5")
"google:gemini-2.5-pro"@ai-sdk/googlegoogle("gemini-2.5-pro")

Both "provider:model" and "provider/model" separators are supported and work identically.

<Callout type="info" title="Need a different AI SDK or full control?"> The [Custom Agent](/built-in-agent/custom-agent) lets you bring your own AI SDK, TanStack AI, or any custom LLM backend while CopilotKit handles the rest. </Callout>