# ![Fireworks AI logo](https://models.dev/logos/fireworks-ai.svg)Fireworks AI

Access 14 Fireworks AI models through Mastra's model router. Authentication is handled automatically using the `FIREWORKS_API_KEY` environment variable.

Learn more in the [Fireworks AI documentation](https://fireworks.ai/docs/).

```bash
FIREWORKS_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: "fireworks-ai/accounts/fireworks/models/deepseek-v3p1"
});

// 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 [Fireworks AI documentation](https://fireworks.ai/docs/) for details.

## Models

| Model                                                     | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
| --------------------------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
| `fireworks-ai/accounts/fireworks/models/deepseek-v3p1`    | 164K    |       |           |       |       |       | $0.56      | $2          |
| `fireworks-ai/accounts/fireworks/models/deepseek-v3p2`    | 160K    |       |           |       |       |       | $0.56      | $2          |
| `fireworks-ai/accounts/fireworks/models/glm-4p5`          | 131K    |       |           |       |       |       | $0.55      | $2          |
| `fireworks-ai/accounts/fireworks/models/glm-4p5-air`      | 131K    |       |           |       |       |       | $0.22      | $0.88       |
| `fireworks-ai/accounts/fireworks/models/glm-4p7`          | 198K    |       |           |       |       |       | $0.60      | $2          |
| `fireworks-ai/accounts/fireworks/models/glm-5`            | 203K    |       |           |       |       |       | $1         | $3          |
| `fireworks-ai/accounts/fireworks/models/gpt-oss-120b`     | 131K    |       |           |       |       |       | $0.15      | $0.60       |
| `fireworks-ai/accounts/fireworks/models/gpt-oss-20b`      | 131K    |       |           |       |       |       | $0.05      | $0.20       |
| `fireworks-ai/accounts/fireworks/models/kimi-k2-instruct` | 128K    |       |           |       |       |       | $1         | $3          |
| `fireworks-ai/accounts/fireworks/models/kimi-k2-thinking` | 256K    |       |           |       |       |       | $0.60      | $3          |
| `fireworks-ai/accounts/fireworks/models/kimi-k2p5`        | 256K    |       |           |       |       |       | $0.60      | $3          |
| `fireworks-ai/accounts/fireworks/models/minimax-m2p1`     | 200K    |       |           |       |       |       | $0.30      | $1          |
| `fireworks-ai/accounts/fireworks/models/minimax-m2p5`     | 197K    |       |           |       |       |       | $0.30      | $1          |
| `fireworks-ai/accounts/fireworks/routers/kimi-k2p5-turbo` | 256K    |       |           |       |       |       | —          | —           |

## Advanced configuration

### Custom headers

```typescript
const agent = new Agent({
  id: "custom-agent",
  name: "custom-agent",
  model: {
    url: "https://api.fireworks.ai/inference/v1/",
    id: "fireworks-ai/accounts/fireworks/models/deepseek-v3p1",
    apiKey: process.env.FIREWORKS_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
      ? "fireworks-ai/accounts/fireworks/routers/kimi-k2p5-turbo"
      : "fireworks-ai/accounts/fireworks/models/deepseek-v3p1";
  }
});
```