Back to Mastra

FastRouter | Models

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

2025-12-185.7 KB
Original Source

FastRouter

Access 14 FastRouter models through Mastra's model router. Authentication is handled automatically using the FASTROUTER_API_KEY environment variable.

Learn more in the FastRouter documentation.

bash
FASTROUTER_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: "fastrouter/anthropic/claude-opus-4.1"
});

// 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 FastRouter documentation for details.

:::

Models

<ProviderModelsTable models={[ { "model": "fastrouter/anthropic/claude-opus-4.1", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 32000, "inputCost": 15, "outputCost": 75 }, { "model": "fastrouter/anthropic/claude-sonnet-4", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 200000, "maxOutput": 64000, "inputCost": 3, "outputCost": 15 }, { "model": "fastrouter/deepseek-ai/deepseek-r1-distill-llama-70b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": true, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 0.03, "outputCost": 0.14 }, { "model": "fastrouter/google/gemini-2.5-flash", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.3, "outputCost": 2.5 }, { "model": "fastrouter/google/gemini-2.5-pro", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 1.25, "outputCost": 10 }, { "model": "fastrouter/moonshotai/kimi-k2", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 131072, "maxOutput": 32768, "inputCost": 0.55, "outputCost": 2.2 }, { "model": "fastrouter/openai/gpt-4.1", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 1047576, "maxOutput": 32768, "inputCost": 2, "outputCost": 8 }, { "model": "fastrouter/openai/gpt-5", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 400000, "maxOutput": 128000, "inputCost": 1.25, "outputCost": 10 }, { "model": "fastrouter/openai/gpt-5-mini", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 400000, "maxOutput": 128000, "inputCost": 0.25, "outputCost": 2 }, { "model": "fastrouter/openai/gpt-5-nano", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 400000, "maxOutput": 128000, "inputCost": 0.05, "outputCost": 0.4 }, { "model": "fastrouter/openai/gpt-oss-120b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 32768, "inputCost": 0.15, "outputCost": 0.6 }, { "model": "fastrouter/openai/gpt-oss-20b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 65536, "inputCost": 0.05, "outputCost": 0.2 }, { "model": "fastrouter/qwen/qwen3-coder", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": false, "contextWindow": 262144, "maxOutput": 66536, "inputCost": 0.3, "outputCost": 1.2 }, { "model": "fastrouter/x-ai/grok-4", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 256000, "maxOutput": 64000, "inputCost": 3, "outputCost": 15 } ]} />

Advanced configuration

Custom headers

typescript
const agent = new Agent({
  id: "custom-agent",
  name: "custom-agent",
  model: {
    url: "https://go.fastrouter.ai/api/v1",
    id: "fastrouter/anthropic/claude-opus-4.1",
    apiKey: process.env.FASTROUTER_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
      ? "fastrouter/x-ai/grok-4"
      : "fastrouter/anthropic/claude-opus-4.1";
  }
});