# ![Deep Infra logo](https://models.dev/logos/deepinfra.svg)Deep Infra

Access 27 Deep Infra models through Mastra's model router. Authentication is handled automatically using the `DEEPINFRA_API_KEY` environment variable.

Learn more in the [Deep Infra documentation](https://deepinfra.com/models).

```bash
DEEPINFRA_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: "deepinfra/MiniMaxAI/MiniMax-M2"
});

// 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);
}
```

## Models

| Model                                                         | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
| ------------------------------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
| `deepinfra/anthropic/claude-3-7-sonnet-latest`                | 200K    |       |           |       |       |       | $3         | $17         |
| `deepinfra/anthropic/claude-4-opus`                           | 200K    |       |           |       |       |       | $17        | $83         |
| `deepinfra/deepseek-ai/DeepSeek-R1-0528`                      | 164K    |       |           |       |       |       | $0.50      | $2          |
| `deepinfra/deepseek-ai/DeepSeek-V3.2`                         | 164K    |       |           |       |       |       | $0.26      | $0.38       |
| `deepinfra/meta-llama/Llama-3.1-70B-Instruct`                 | 131K    |       |           |       |       |       | $0.40      | $0.40       |
| `deepinfra/meta-llama/Llama-3.1-70B-Instruct-Turbo`           | 131K    |       |           |       |       |       | $0.40      | $0.40       |
| `deepinfra/meta-llama/Llama-3.1-8B-Instruct`                  | 131K    |       |           |       |       |       | $0.02      | $0.05       |
| `deepinfra/meta-llama/Llama-3.1-8B-Instruct-Turbo`            | 131K    |       |           |       |       |       | $0.02      | $0.03       |
| `deepinfra/meta-llama/Llama-3.3-70B-Instruct-Turbo`           | 131K    |       |           |       |       |       | $0.10      | $0.32       |
| `deepinfra/meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8` | 1.0M    |       |           |       |       |       | $0.15      | $0.60       |
| `deepinfra/meta-llama/Llama-4-Scout-17B-16E-Instruct`         | 10.0M   |       |           |       |       |       | $0.08      | $0.30       |
| `deepinfra/MiniMaxAI/MiniMax-M2`                              | 262K    |       |           |       |       |       | $0.25      | $1          |
| `deepinfra/MiniMaxAI/MiniMax-M2.1`                            | 197K    |       |           |       |       |       | $0.28      | $1          |
| `deepinfra/MiniMaxAI/MiniMax-M2.5`                            | 205K    |       |           |       |       |       | $0.27      | $0.95       |
| `deepinfra/moonshotai/Kimi-K2-Instruct`                       | 131K    |       |           |       |       |       | $0.50      | $2          |
| `deepinfra/moonshotai/Kimi-K2-Instruct-0905`                  | 262K    |       |           |       |       |       | $0.40      | $2          |
| `deepinfra/moonshotai/Kimi-K2-Thinking`                       | 131K    |       |           |       |       |       | $0.47      | $2          |
| `deepinfra/moonshotai/Kimi-K2.5`                              | 262K    |       |           |       |       |       | $0.50      | $3          |
| `deepinfra/openai/gpt-oss-120b`                               | 131K    |       |           |       |       |       | $0.05      | $0.24       |
| `deepinfra/openai/gpt-oss-20b`                                | 131K    |       |           |       |       |       | $0.03      | $0.14       |
| `deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct`               | 262K    |       |           |       |       |       | $0.40      | $2          |
| `deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo`         | 262K    |       |           |       |       |       | $0.30      | $1          |
| `deepinfra/zai-org/GLM-4.6`                                   | 205K    |       |           |       |       |       | $0.43      | $2          |
| `deepinfra/zai-org/GLM-4.6V`                                  | 205K    |       |           |       |       |       | $0.30      | $0.90       |
| `deepinfra/zai-org/GLM-4.7`                                   | 203K    |       |           |       |       |       | $0.43      | $2          |
| `deepinfra/zai-org/GLM-4.7-Flash`                             | 203K    |       |           |       |       |       | $0.06      | $0.40       |
| `deepinfra/zai-org/GLM-5`                                     | 203K    |       |           |       |       |       | $0.80      | $3          |

## Advanced configuration

### Custom headers

```typescript
const agent = new Agent({
  id: "custom-agent",
  name: "custom-agent",
  model: {
    id: "deepinfra/MiniMaxAI/MiniMax-M2",
    apiKey: process.env.DEEPINFRA_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
      ? "deepinfra/zai-org/GLM-5"
      : "deepinfra/MiniMaxAI/MiniMax-M2";
  }
});
```

## Direct provider installation

This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the [package documentation](https://www.npmjs.com/package/@ai-sdk/deepinfra) for more details.

**npm**:

```bash
npm install @ai-sdk/deepinfra
```

**pnpm**:

```bash
pnpm add @ai-sdk/deepinfra
```

**Yarn**:

```bash
yarn add @ai-sdk/deepinfra
```

**Bun**:

```bash
bun add @ai-sdk/deepinfra
```

For detailed provider-specific documentation, see the [AI SDK Deep Infra provider docs](https://ai-sdk.dev/providers/ai-sdk-providers/deepinfra).