Providers
Configure OpenAI, OpenRouter, Anthropic, Gemini, Ollama, LM Studio, llama.cpp, Bedrock, or Vertex.
The SDK ships 9 built-in providers. Pick one (or several), set the env var, and pass a model id with the right prefix.
Provider summary
| Provider | Env var(s) | Auth | Model id prefix |
|---|---|---|---|
| OpenAI | OPENAI_API_KEY | API key | openai/gpt-4o-mini, ... |
| OpenRouter | OPENROUTER_API_KEY | API key | openai/gpt-4o-mini, anthropic/claude-..., ... |
| Anthropic | ANTHROPIC_API_KEY | API key | claude-sonnet-4-6, claude-opus-4-7, ... |
| Gemini | GEMINI_API_KEY | API key | google/gemini-2.0-flash-001, ... |
| Ollama | none (local) | none | ollama/llama3.2:3b, ... |
| LM Studio | none (local) | none | lmstudio/<model>, ... |
| llama.cpp | none (local) | none | llamacpp/<model>, ... |
| AWS Bedrock | AWS credential chain or AWS_BEARER_TOKEN_BEDROCK | aws_bearer | bedrock/us.anthropic.claude-sonnet-4-5-... |
| GCP Vertex | GOOGLE_APPLICATION_CREDENTIALS or ADC | gcp_oauth | vertex/anthropic/... or vertex/google/gemini-... |
OpenAI
export OPENAI_API_KEY="sk-..."const agent = await Agent.create({
apiKey: process.env.OPENAI_API_KEY,
model: { id: "openai/gpt-4o-mini" },
});OpenRouter
OpenRouter aggregates 300+ models behind one API. Cheapest path for prototyping.
export OPENROUTER_API_KEY="sk-or-v1-..."const agent = await Agent.create({
apiKey: process.env.OPENROUTER_API_KEY,
model: { id: "openai/gpt-4o-mini" }, // any OpenRouter-supported model id
});Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."const agent = await Agent.create({
apiKey: process.env.ANTHROPIC_API_KEY,
model: { id: "claude-sonnet-4-6" },
});Gemini
export GEMINI_API_KEY="..."const agent = await Agent.create({
apiKey: process.env.GEMINI_API_KEY,
model: { id: "google/gemini-2.0-flash-001" },
});Ollama (local)
# Install + start Ollama: https://ollama.com
ollama serve &
ollama pull llama3.2:3bconst agent = await Agent.create({
apiKey: "ollama", // any non-empty placeholder — Ollama ignores Authorization
model: { id: "ollama/llama3.2:3b" },
});Set OLLAMA_HOST=http://192.168.1.50:11434 to point at a remote box.
LM Studio (local)
LM Studio defaults to port 1234.
const agent = await Agent.create({
apiKey: "lmstudio",
model: { id: "lmstudio/<your-loaded-model>" },
});Override with LMSTUDIO_HOST=http://localhost:1234.
llama.cpp (local)
llama.cpp server defaults to port 8080.
const agent = await Agent.create({
apiKey: "llamacpp",
model: { id: "llamacpp/<model>" },
});Override with LLAMACPP_HOST=http://localhost:8080.
AWS Bedrock
Two auth paths. Either set a Bearer token directly:
export AWS_BEARER_TOKEN_BEDROCK="bedrock-api-key-..."Or rely on the standard AWS credential chain (~/.aws/credentials, IAM role, env vars) plus the optional peer:
pnpm add @aws/bedrock-token-generator @aws-sdk/credential-providersThen:
const agent = await Agent.create({
apiKey: process.env.AWS_BEARER_TOKEN_BEDROCK ?? "__bedrock_lazy_token__",
model: { id: "bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0" },
});Common gotcha: the AWS account needs to complete the "Anthropic use case details" form in the Bedrock Console (separate from "Model access"). Without it, every request returns ResourceNotFoundException.
GCP Vertex AI
Install the required peer:
pnpm add google-auth-librarySet up ADC:
gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT="your-project-id"Then pick a dialect:
// Claude on Vertex:
model: { id: "vertex/anthropic/claude-sonnet-4-5-20250929" }
// Gemini on Vertex:
model: { id: "vertex/google/gemini-2.0-flash-001" }Multi-provider fallback
You can list a fallback chain — if the primary fails, the SDK tries the next:
const agent = await Agent.create({
apiKey: process.env.OPENROUTER_API_KEY,
model: { id: "openai/gpt-4o-mini" },
providers: {
routes: [{ provider: "openrouter" }],
fallback: ["openai", "anthropic"],
},
});See the Agent concept for fallback semantics and the Credential pool for multi-key rotation.
Next
Build your first real agent with tools, persistence, and memory.