# ![FastRouter logo](https://models.dev/logos/fastrouter.svg)FastRouter

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

Learn more in the [FastRouter documentation](https://fastrouter.ai/models).

```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](https://fastrouter.ai/models) for details.

## Models

| Model                                                  | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
| ------------------------------------------------------ | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
| `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       |
| `fastrouter/google/gemini-2.5-flash`                   | 1.0M    |       |           |       |       |       | $0.30      | $3          |
| `fastrouter/google/gemini-2.5-pro`                     | 1.0M    |       |           |       |       |       | $1         | $10         |
| `fastrouter/moonshotai/kimi-k2`                        | 131K    |       |           |       |       |       | $0.55      | $2          |
| `fastrouter/openai/gpt-4.1`                            | 1.0M    |       |           |       |       |       | $2         | $8          |
| `fastrouter/openai/gpt-5`                              | 400K    |       |           |       |       |       | $1         | $10         |
| `fastrouter/openai/gpt-5-mini`                         | 400K    |       |           |       |       |       | $0.25      | $2          |
| `fastrouter/openai/gpt-5-nano`                         | 400K    |       |           |       |       |       | $0.05      | $0.40       |
| `fastrouter/openai/gpt-oss-120b`                       | 131K    |       |           |       |       |       | $0.15      | $0.60       |
| `fastrouter/openai/gpt-oss-20b`                        | 131K    |       |           |       |       |       | $0.05      | $0.20       |
| `fastrouter/qwen/qwen3-coder`                          | 262K    |       |           |       |       |       | $0.30      | $1          |
| `fastrouter/x-ai/grok-4`                               | 256K    |       |           |       |       |       | $3         | $15         |
| `fastrouter/z-ai/glm-5`                                | 205K    |       |           |       |       |       | $0.95      | $3          |

## 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/z-ai/glm-5"
      : "fastrouter/anthropic/claude-opus-4.1";
  }
});
```