Skip to main content

FastRouter logoFastRouter

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.

FASTROUTER_API_KEY=your-api-key
import { Agent } from "@mastra/core";

const agent = new 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

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
fastrouter/anthropic/claude-opus-4.1200K$15$75
fastrouter/anthropic/claude-sonnet-4200K$3$15
fastrouter/deepseek-ai/deepseek-r1-distill-llama-70b131K$0.03$0.14
fastrouter/google/gemini-2.5-flash1.0M$0.30$3
fastrouter/google/gemini-2.5-pro1.0M$1$10
fastrouter/moonshotai/kimi-k2131K$0.55$2
fastrouter/openai/gpt-4.11.0M$2$8
fastrouter/openai/gpt-5400K$1$10
fastrouter/openai/gpt-5-mini400K$0.25$2
fastrouter/openai/gpt-5-nano400K$0.05$0.40
fastrouter/openai/gpt-oss-120b131K$0.15$0.60
fastrouter/openai/gpt-oss-20b131K$0.05$0.20
fastrouter/qwen/qwen3-coder262K$0.30$1
fastrouter/x-ai/grok-4256K$3$15
14 available models

Advanced Configuration

Custom Headers

const agent = new 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

const agent = new Agent({
name: "dynamic-agent",
model: ({ runtimeContext }) => {
const useAdvanced = runtimeContext.task === "complex";
return useAdvanced
? "fastrouter/x-ai/grok-4"
: "fastrouter/anthropic/claude-opus-4.1";
}
});

On this page