Back to Mastra

AgentRouter | Models | Mastra

docs/src/content/en/models/providers/agentrouter.mdx

2025-12-187.2 KB
Original Source

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.

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 for details.

:::

Models

<ProviderModelsTable models={[ { "model": "agentrouter/claude-3-5-haiku-20241022", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 200000, "maxOutput": 8192, "inputCost": 1, "outputCost": 5 }, { "model": "agentrouter/claude-3-5-sonnet-20240620", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 200000, "maxOutput": 8192, "inputCost": 3, "outputCost": 15 }, { "model": "agentrouter/claude-3-5-sonnet-20241022", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 200000, "maxOutput": 8192, "inputCost": 3, "outputCost": 15 }, { "model": "agentrouter/claude-3-7-sonnet-20250219", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 3, "outputCost": 15 }, { "model": "agentrouter/claude-3-7-sonnet-20250219-thinking", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 3, "outputCost": 15 }, { "model": "agentrouter/claude-haiku-4-5-20251001", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 2, "outputCost": 4 }, { "model": "agentrouter/claude-opus-4-20250514", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 32000, "inputCost": 21, "outputCost": 105 }, { "model": "agentrouter/claude-opus-4-20250514-thinking", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 32000, "inputCost": 2, "outputCost": 10 }, { "model": "agentrouter/claude-sonnet-4-20250514", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 3, "outputCost": 15 }, { "model": "agentrouter/claude-sonnet-4-20250514-thinking", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 2, "outputCost": 10 }, { "model": "agentrouter/claude-sonnet-4-5-20250929", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 1000000, "maxOutput": 64000, "inputCost": 6, "outputCost": 30 }, { "model": "agentrouter/deepseek-r1-0528", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 128000, "maxOutput": 128000, "inputCost": 0.3, "outputCost": 0.045 }, { "model": "agentrouter/deepseek-v3.1", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 128000, "maxOutput": 8192, "inputCost": 0.3, "outputCost": 0.045 }, { "model": "agentrouter/deepseek-v3.2", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 128000, "maxOutput": 8192, "inputCost": 0.3, "outputCost": 0.045 }, { "model": "agentrouter/gemini-3-pro-preview", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1000000, "maxOutput": 64000, "inputCost": 2, "outputCost": 8 }, { "model": "agentrouter/glm-4.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 131072, "maxOutput": 98304, "inputCost": 0.003, "outputCost": null }, { "model": "agentrouter/glm-4.6", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 204800, "maxOutput": 131072, "inputCost": 0.003, "outputCost": null }, { "model": "agentrouter/gpt-5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 1280000, "maxOutput": 1280000, "inputCost": null, "outputCost": null }, { "model": "agentrouter/gpt-5.1", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 400000, "maxOutput": 128000, "inputCost": 2, "outputCost": 2 }, { "model": "agentrouter/kimi-k2-thinking", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 262144, "maxOutput": 262144, "inputCost": 0.002, "outputCost": null } ]} />

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";
  }
});