# ![Together AI logo](https://models.dev/logos/togetherai.svg)Together AI

Access 13 Together AI models through Mastra's model router. Authentication is handled automatically using the `TOGETHER_API_KEY` environment variable.

Learn more in the [Together AI documentation](https://docs.together.ai/docs/serverless-models).

```bash
TOGETHER_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: "togetherai/MiniMaxAI/MiniMax-M2.5"
});

// 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 |
| ---------------------------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- |
| `togetherai/deepseek-ai/DeepSeek-R1`                 | 164K    |       |           |       |       |       | $3         | $7          |
| `togetherai/deepseek-ai/DeepSeek-V3`                 | 131K    |       |           |       |       |       | $1         | $1          |
| `togetherai/deepseek-ai/DeepSeek-V3-1`               | 131K    |       |           |       |       |       | $0.60      | $2          |
| `togetherai/essentialai/Rnj-1-Instruct`              | 33K     |       |           |       |       |       | $0.15      | $0.15       |
| `togetherai/meta-llama/Llama-3.3-70B-Instruct-Turbo` | 131K    |       |           |       |       |       | $0.88      | $0.88       |
| `togetherai/MiniMaxAI/MiniMax-M2.5`                  | 205K    |       |           |       |       |       | $0.30      | $1          |
| `togetherai/moonshotai/Kimi-K2.5`                    | 262K    |       |           |       |       |       | $0.50      | $3          |
| `togetherai/openai/gpt-oss-120b`                     | 131K    |       |           |       |       |       | $0.15      | $0.60       |
| `togetherai/Qwen/Qwen3-235B-A22B-Instruct-2507-tput` | 262K    |       |           |       |       |       | $0.20      | $0.60       |
| `togetherai/Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8` | 262K    |       |           |       |       |       | $2         | $2          |
| `togetherai/Qwen/Qwen3-Coder-Next-FP8`               | 262K    |       |           |       |       |       | $0.50      | $1          |
| `togetherai/Qwen/Qwen3.5-397B-A17B`                  | 262K    |       |           |       |       |       | $0.60      | $4          |
| `togetherai/zai-org/GLM-5`                           | 203K    |       |           |       |       |       | $1         | $3          |

## Advanced configuration

### Custom headers

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

## 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/togetherai) for more details.

**npm**:

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

**pnpm**:

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

**Yarn**:

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

**Bun**:

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

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