# ![AgentRouter logo](https://models.dev/logos/agentrouter.svg)AgentRouter Access 20 AgentRouter models through Mastra's model router. Authentication is handled automatically using the `AGENTROUTER_API_KEY` environment variable. Learn more in the [AgentRouter documentation](https://docs.agentrouter.org). ```bash AGENTROUTER_API_KEY=your-api-key ``` ```typescript import { Agent } from "@mastra/core/agent"; const agent = new Agent({ id: "my-agent", name: "My Agent", instructions: "You are a helpful assistant", model: "agentrouter/claude-3-5-haiku-20241022" }); // Generate a response const response = await agent.generate("Hello!"); // Stream a response const stream = await agent.stream("Tell me a story"); for await (const chunk of stream) { console.log(chunk); } ``` > **Info:** Mastra uses the OpenAI-compatible `/chat/completions` endpoint. Some provider-specific features may not be available. Check the [AgentRouter documentation](https://docs.agentrouter.org) for details. ## Models | Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M | | ------------------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- | | `agentrouter/claude-3-5-haiku-20241022` | 200K | | | | | | $1 | $5 | | `agentrouter/claude-3-5-sonnet-20240620` | 200K | | | | | | $3 | $15 | | `agentrouter/claude-3-5-sonnet-20241022` | 200K | | | | | | $3 | $15 | | `agentrouter/claude-3-7-sonnet-20250219` | 200K | | | | | | $3 | $15 | | `agentrouter/claude-3-7-sonnet-20250219-thinking` | 200K | | | | | | $3 | $15 | | `agentrouter/claude-haiku-4-5-20251001` | 200K | | | | | | $2 | $4 | | `agentrouter/claude-opus-4-20250514` | 200K | | | | | | $21 | $105 | | `agentrouter/claude-opus-4-20250514-thinking` | 200K | | | | | | $2 | $10 | | `agentrouter/claude-sonnet-4-20250514` | 200K | | | | | | $3 | $15 | | `agentrouter/claude-sonnet-4-20250514-thinking` | 200K | | | | | | $2 | $10 | | `agentrouter/claude-sonnet-4-5-20250929` | 1.0M | | | | | | $6 | $30 | | `agentrouter/deepseek-r1-0528` | 128K | | | | | | $0.30 | $0.04 | | `agentrouter/deepseek-v3.1` | 128K | | | | | | $0.30 | $0.04 | | `agentrouter/deepseek-v3.2` | 128K | | | | | | $0.30 | $0.04 | | `agentrouter/gemini-3-pro-preview` | 1.0M | | | | | | $2 | $8 | | `agentrouter/glm-4.5` | 131K | | | | | | $0.00 | — | | `agentrouter/glm-4.6` | 205K | | | | | | $0.00 | — | | `agentrouter/gpt-5` | 1.3M | | | | | | — | — | | `agentrouter/gpt-5.1` | 400K | | | | | | $2 | $2 | | `agentrouter/kimi-k2-thinking` | 262K | | | | | | $0.00 | — | ## Advanced Configuration ### Custom Headers ```typescript const agent = new Agent({ id: "custom-agent", name: "custom-agent", model: { url: "https://agentrouter.org/v1", id: "agentrouter/claude-3-5-haiku-20241022", apiKey: process.env.AGENTROUTER_API_KEY, headers: { "X-Custom-Header": "value" } } }); ``` ### Dynamic Model Selection ```typescript const agent = new Agent({ id: "dynamic-agent", name: "Dynamic Agent", model: ({ requestContext }) => { const useAdvanced = requestContext.task === "complex"; return useAdvanced ? "agentrouter/kimi-k2-thinking" : "agentrouter/claude-3-5-haiku-20241022"; } }); ```