> ## Documentation Index
> Fetch the complete documentation index at: https://platform.minimax.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AI SDK

> Call MiniMax models using the AI SDK

To meet developers' needs for the [AI SDK](https://ai-sdk.dev) ecosystem, MiniMax provides an official community provider. With simple configuration, you can integrate MiniMax capabilities into the AI SDK ecosystem.

## Quick Start

### 1. Install AI SDK and MiniMax Provider

<CodeGroup>
  ```bash npm theme={null}
  npm install ai vercel-minimax-ai-provider
  ```

  ```bash pnpm theme={null}
  pnpm add ai vercel-minimax-ai-provider
  ```
</CodeGroup>

### 2. Configure Environment Variables

```bash theme={null}
export MINIMAX_API_KEY=${YOUR_API_KEY}
```

### 3. Call API

```typescript TypeScript theme={null}
import { minimax } from 'vercel-minimax-ai-provider';
import { generateText } from 'ai';

const { text, reasoning } = await generateText({
  model: minimax('MiniMax-M2.7'),
  system: 'You are a helpful assistant.',
  prompt: 'Hi, how are you?',
});

if (reasoning) {
  console.log(`Thinking:\n${reasoning}\n`);
}
console.log(`Text:\n${text}\n`);
```

### 4. Important Note

In multi-turn function call conversations, the complete model response (i.e., the assistant message) must be appended to the conversation history to maintain the continuity of the reasoning chain.

* Append the full `result.response.messages` to the message history (includes all assistant and tool messages)

## Supported Models

When using the AI SDK, the `MiniMax-M2.7` `MiniMax-M2.7-highspeed` `MiniMax-M2.5` `MiniMax-M2.5-highspeed` `MiniMax-M2.1` `MiniMax-M2.1-highspeed` `MiniMax-M2` model is supported:

| Model Name             | Context Window | Description                                                                                                                                   |
| :--------------------- | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
| MiniMax-M2.7           | 204,800        | **Beginning the journey of recursive self-improvement** (output speed approximately 60 tps)                                                   |
| MiniMax-M2.7-highspeed | 204,800        | **M2.7 Highspeed: Same performance, faster and more agile (output speed approximately 100 tps)**                                              |
| MiniMax-M2.5           | 204,800        | **Peak Performance. Ultimate Value. Master the Complex (output speed approximately 60 tps)**                                                  |
| MiniMax-M2.5-highspeed | 204,800        | **M2.5 highspeed: Same performance, faster and more agile (output speed approximately 100 tps)**                                              |
| MiniMax-M2.1           | 204,800        | **Powerful Multi-Language Programming Capabilities with Comprehensively Enhanced Programming Experience (output speed approximately 60 tps)** |
| MiniMax-M2.1-highspeed | 204,800        | **Faster and More Agile (output speed approximately 100 tps)**                                                                                |
| MiniMax-M2             | 204,800        | **Agentic capabilities, Advanced reasoning**                                                                                                  |

<Note>
  For details on how tps (Tokens Per Second) is calculated, please refer to [FAQ > About APIs](/faq/about-apis#q-how-is-tps-tokens-per-second-calculated-for-text-models).
</Note>

<Note>
  The AI SDK compatibility interface currently only supports the
  `MiniMax-M2.7` `MiniMax-M2.7-highspeed` `MiniMax-M2.5` `MiniMax-M2.5-highspeed` `MiniMax-M2.1` `MiniMax-M2.1-highspeed` `MiniMax-M2` model. For other models, please use the standard MiniMax API
  interface.
</Note>

## Compatibility

### Supported Parameters

When using the AI SDK, we support the following input parameters:

| Parameter     | Support Status  | Description                                                                                                                                         |
| :------------ | :-------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`       | Fully supported | supports `MiniMax-M2.7` `MiniMax-M2.7-highspeed` `MiniMax-M2.5` `MiniMax-M2.5-highspeed` `MiniMax-M2.1` `MiniMax-M2.1-highspeed` `MiniMax-M2` model |
| `messages`    | Partial support | Supports text and tool calls, no image/document input                                                                                               |
| `maxTokens`   | Fully supported | Maximum number of tokens to generate                                                                                                                |
| `system`      | Fully supported | System prompt                                                                                                                                       |
| `temperature` | Fully supported | Range \[0, 2], controls output randomness, recommended value: 1                                                                                     |
| `toolChoice`  | Fully supported | Tool selection strategy                                                                                                                             |
| `tools`       | Fully supported | Tool definitions                                                                                                                                    |
| `topP`        | Fully supported | Nucleus sampling parameter, range \[0, 1]. Default 0.9 for `MiniMax-M2.x` models                                                                    |

### Messages Field Support

| Field Type           | Support Status  | Description                   |
| :------------------- | :-------------- | :---------------------------- |
| `role="user"`        | Fully supported | User text messages            |
| `role="assistant"`   | Fully supported | Assistant responses           |
| `role="tool"`        | Fully supported | Tool call results             |
| `type="text"`        | Fully supported | Text content                  |
| `type="tool-call"`   | Fully supported | Tool calls                    |
| `type="tool-result"` | Fully supported | Tool call results             |
| `type="image"`       | Not supported   | Image input not supported yet |
| `type="file"`        | Not supported   | File input not supported yet  |

## Examples

### Streaming Response

```typescript TypeScript theme={null}
import { minimax } from 'vercel-minimax-ai-provider';
import { streamText } from 'ai';

console.log("Starting stream response...\n");
console.log("=".repeat(60));
console.log("Thinking Process:");
console.log("=".repeat(60));

const result = streamText({
  model: minimax('MiniMax-M2.7'),
  system: 'You are a helpful assistant.',
  prompt: 'Hi, how are you?',
  onError({ error }) {
    console.error(error);
  },
});

let inText = false;

for await (const part of result.fullStream) {
  if (part.type === 'reasoning') {
    // Stream output thinking process
    process.stdout.write(part.text);
  } else if (part.type === 'text') {
    if (!inText) {
      inText = true;
      console.log("\n" + "=".repeat(60));
      console.log("Response Content:");
      console.log("=".repeat(60));
    }
    // Stream output text content
    process.stdout.write(part.text);
  }
}

console.log("\n");
```

## Important Notes

<Warning>
  1. The AI SDK compatibility interface currently only supports the `MiniMax-M2.7` `MiniMax-M2.7-highspeed` `MiniMax-M2.5` `MiniMax-M2.5-highspeed` `MiniMax-M2.1` `MiniMax-M2.1-highspeed` `MiniMax-M2` model

  2. The `temperature` parameter range is \[0, 2], values outside this range will return an error

  3. Image and document type inputs are not currently supported

  4. The default `minimax` provider instance uses the Anthropic-compatible API format. Use `minimaxOpenAI` if you need the OpenAI-compatible format.

  5. For more information, see the [MiniMax AI Provider on AI SDK](https://ai-sdk.dev/providers/community-providers/minimax) and the [GitHub repository](https://github.com/MiniMax-AI/vercel-minimax-ai-provider)
</Warning>
