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);
}
OpenAI Compatibility
Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the FastRouter documentation for details.
Models
| Model | Image | Audio | Video | Tools | Streaming | Context Window |
|---|---|---|---|---|---|---|
fastrouter/moonshotai/kimi-k2 | ✗ | ✗ | ✗ | ✓ | ✗ | 131,072 |
fastrouter/x-ai/grok-4 | ✗ | ✗ | ✗ | ✓ | ✗ | 256,000 |
fastrouter/google/gemini-2.5-flash | ✓ | ✗ | ✗ | ✓ | ✗ | 1,048,576 |
fastrouter/google/gemini-2.5-pro | ✓ | ✗ | ✗ | ✓ | ✗ | 1,048,576 |
fastrouter/openai/gpt-5-nano | ✓ | ✗ | ✗ | ✓ | ✗ | 400,000 |
fastrouter/openai/gpt-4.1 | ✓ | ✗ | ✗ | ✓ | ✗ | 1,047,576 |
fastrouter/openai/gpt-5-mini | ✓ | ✗ | ✗ | ✓ | ✗ | 400,000 |
fastrouter/openai/gpt-oss-20b | ✗ | ✗ | ✗ | ✓ | ✗ | 131,072 |
fastrouter/openai/gpt-oss-120b | ✗ | ✗ | ✗ | ✓ | ✗ | 131,072 |
fastrouter/openai/gpt-5 | ✓ | ✗ | ✗ | ✓ | ✗ | 400,000 |
fastrouter/qwen/qwen3-coder | ✗ | ✗ | ✗ | ✓ | ✗ | 262,144 |
fastrouter/anthropic/claude-opus-4.1 | ✓ | ✗ | ✗ | ✓ | ✗ | 200,000 |
fastrouter/anthropic/claude-sonnet-4 | ✓ | ✗ | ✗ | ✓ | ✗ | 200,000 |
fastrouter/deepseek-ai/deepseek-r1-distill-llama-70b | ✗ | ✗ | ✗ | ✗ | ✗ | 131,072 |
Advanced Configuration
Custom Headers
const agent = new Agent({
name: "custom-agent",
model: {
url: "https://go.fastrouter.ai/api/v1",
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/x-ai/grok-4"
: "fastrouter/anthropic/claude-opus-4.1";
},
});