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 .
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);
}
Mastra uses the OpenAI-compatible /chat/completions
endpoint. Some provider-specific features may not be available. Check the FastRouter documentation for details.
Models
Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
---|---|---|---|---|---|---|---|---|
fastrouter/moonshotai/kimi-k2 | 131K | $0.55 | $2 | |||||
fastrouter/x-ai/grok-4 | 256K | $3 | $15 | |||||
fastrouter/google/gemini-2.5-flash | 1.0M | $0.30 | $3 | |||||
fastrouter/google/gemini-2.5-pro | 1.0M | $1 | $10 | |||||
fastrouter/openai/gpt-5-nano | 400K | $0.05 | $0.40 | |||||
fastrouter/openai/gpt-4.1 | 1.0M | $2 | $8 | |||||
fastrouter/openai/gpt-5-mini | 400K | $0.25 | $2 | |||||
fastrouter/openai/gpt-oss-20b | 131K | $0.05 | $0.20 | |||||
fastrouter/openai/gpt-oss-120b | 131K | $0.15 | $0.60 | |||||
fastrouter/openai/gpt-5 | 400K | $1 | $10 | |||||
fastrouter/qwen/qwen3-coder | 262K | $0.30 | $1 | |||||
fastrouter/anthropic/claude-opus-4.1 | 200K | $15 | $75 | |||||
fastrouter/anthropic/claude-sonnet-4 | 200K | $3 | $15 | |||||
fastrouter/deepseek-ai/deepseek-r1-distill-llama-70b | 131K | $0.03 | $0.14 |
Advanced Configuration
Custom Headers
const agent = new Agent({
name: "custom-agent",
model: {
url: "https://go.fastrouter.ai/api/v1/chat/completions",
modelId: "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/anthropic/claude-opus-4.1"
: "fastrouter/anthropic/claude-sonnet-4";
}
});