Skip to content

Commit dc1cfee

Browse files
author
qinjiu
committed
feat: minimax provider
1 parent a9da06b commit dc1cfee

24 files changed

+1324
-24
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
---
2+
title: MiniMax
3+
description: Learn how to use MiniMax's models with the AI SDK.
4+
---
5+
6+
# MiniMax Provider
7+
8+
The [MiniMax](https://www.minimaxi.com) provider offers access to powerful language models through the MiniMax API, including their latest [MiniMax-M2 model](https://platform.minimaxi.com/docs/guides/text-generation).
9+
10+
API keys can be obtained from the [MiniMax Platform](https://platform.minimaxi.com).
11+
12+
## Setup
13+
14+
The MiniMax provider is available via the `@ai-sdk/minimax` module. You can install it with:
15+
16+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
17+
<Tab>
18+
<Snippet text="pnpm add @ai-sdk/minimax" dark />
19+
</Tab>
20+
<Tab>
21+
<Snippet text="npm install @ai-sdk/minimax" dark />
22+
</Tab>
23+
<Tab>
24+
<Snippet text="yarn add @ai-sdk/minimax" dark />
25+
</Tab>
26+
27+
<Tab>
28+
<Snippet text="bun add @ai-sdk/minimax" dark />
29+
</Tab>
30+
</Tabs>
31+
32+
## Provider Instance
33+
34+
The MiniMax provider supports two API compatibility modes:
35+
36+
### OpenAI-Compatible API (Default)
37+
38+
You can import the default provider instance `minimax` from `@ai-sdk/minimax`:
39+
40+
```ts
41+
import { minimax } from '@ai-sdk/minimax';
42+
```
43+
44+
Or explicitly use the OpenAI-compatible instance:
45+
46+
```ts
47+
import { minimaxOpenAI } from '@ai-sdk/minimax';
48+
```
49+
50+
### Anthropic-Compatible API
51+
52+
For Anthropic-compatible API format:
53+
54+
```ts
55+
import { minimaxAnthropic } from '@ai-sdk/minimax';
56+
```
57+
58+
## Custom Configuration
59+
60+
For custom configuration, you can use the `createMinimax` or `createMinimaxAnthropic` functions:
61+
62+
### OpenAI-Compatible Configuration
63+
64+
```ts
65+
import { createMinimax } from '@ai-sdk/minimax';
66+
67+
const minimax = createMinimax({
68+
apiKey: process.env.MINIMAX_API_KEY ?? '',
69+
baseURL: 'https://api.minimaxi.com/v1', // optional, this is the default
70+
});
71+
```
72+
73+
### Anthropic-Compatible Configuration
74+
75+
```ts
76+
import { createMinimaxAnthropic } from '@ai-sdk/minimax';
77+
78+
const minimaxAnthropic = createMinimaxAnthropic({
79+
apiKey: process.env.MINIMAX_API_KEY ?? '',
80+
baseURL: 'https://api.minimaxi.com/anthropic', // optional, this is the default
81+
});
82+
```
83+
84+
### Configuration Options
85+
86+
You can use the following optional settings to customize the MiniMax provider instance:
87+
88+
- **baseURL** _string_
89+
90+
Use a different URL prefix for API calls.
91+
- OpenAI-compatible default: `https://api.minimaxi.com/v1`
92+
- Anthropic-compatible default: `https://api.minimaxi.com/anthropic`
93+
94+
- **apiKey** _string_
95+
96+
API key that is being sent using the `Authorization` header. It defaults to
97+
the `MINIMAX_API_KEY` environment variable.
98+
99+
- **headers** _Record&lt;string,string&gt;_
100+
101+
Custom headers to include in the requests.
102+
103+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_
104+
105+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
106+
107+
## Language Models
108+
109+
You can create language models using a provider instance:
110+
111+
### OpenAI-Compatible
112+
113+
```ts
114+
import { minimax } from '@ai-sdk/minimax';
115+
import { generateText } from 'ai';
116+
117+
const { text } = await generateText({
118+
model: minimax('MiniMax-M2'),
119+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
120+
});
121+
```
122+
123+
### Anthropic-Compatible
124+
125+
```ts
126+
import { minimaxAnthropic } from '@ai-sdk/minimax';
127+
import { generateText } from 'ai';
128+
129+
const { text } = await generateText({
130+
model: minimaxAnthropic('MiniMax-M2'),
131+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
132+
});
133+
```
134+
135+
You can also use the `.chat()` or `.languageModel()` factory methods:
136+
137+
```ts
138+
const model = minimax.chat('MiniMax-M2');
139+
// or
140+
const model = minimax.languageModel('MiniMax-M2');
141+
142+
// For Anthropic-compatible:
143+
const anthropicModel = minimaxAnthropic.chat('MiniMax-M2');
144+
// or
145+
const anthropicModel = minimaxAnthropic.languageModel('MiniMax-M2');
146+
```
147+
148+
MiniMax language models can be used in the `streamText` function
149+
(see [AI SDK Core](/docs/ai-sdk-core)).
150+
151+
## API Compatibility
152+
153+
MiniMax provides two API formats. Both are included in this package:
154+
155+
### When to Use Each Format
156+
157+
- **OpenAI-Compatible** (`minimax`): Use this as your default. It's simpler and works well for most use cases.
158+
- **Anthropic-Compatible** (`minimaxAnthropic`): Use this if you need specific Anthropic features or are migrating from Anthropic.
159+
160+
### Key Differences
161+
162+
The main difference is the API request/response format:
163+
164+
- **OpenAI format**: Uses standard OpenAI chat completion format
165+
- **Anthropic format**: Uses Anthropic Messages API format (requires `anthropic-version` header)
166+
167+
Both formats access the same MiniMax models with the same capabilities.
168+
169+
## Model Capabilities
170+
171+
| Model | Text Generation | Object Generation | Image Input | Tool Usage | Tool Streaming |
172+
| ------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
173+
| `MiniMax-M2` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
174+
175+
<Note>
176+
Please see the [MiniMax docs](https://platform.minimaxi.com/docs) for a full list
177+
of available models and their capabilities. The provider accepts any model ID as a
178+
string for forward compatibility.
179+
</Note>
180+
181+
## Example Usage
182+
183+
### Basic Text Generation
184+
185+
```ts
186+
import { minimax } from '@ai-sdk/minimax';
187+
import { generateText } from 'ai';
188+
189+
const result = await generateText({
190+
model: minimax('MiniMax-M2'),
191+
prompt: 'Explain quantum computing in simple terms.',
192+
});
193+
194+
console.log(result.text);
195+
```
196+
197+
### Streaming
198+
199+
```ts
200+
import { minimax } from '@ai-sdk/minimax';
201+
import { streamText } from 'ai';
202+
203+
const result = streamText({
204+
model: minimax('MiniMax-M2'),
205+
prompt: 'Write a short story about a robot learning to paint.',
206+
});
207+
208+
for await (const chunk of result.textStream) {
209+
process.stdout.write(chunk);
210+
}
211+
```
212+
213+
### With Tools
214+
215+
```ts
216+
import { minimax } from '@ai-sdk/minimax';
217+
import { generateText } from 'ai';
218+
import { z } from 'zod';
219+
220+
const result = await generateText({
221+
model: minimax('MiniMax-M2'),
222+
tools: {
223+
weather: {
224+
description: 'Get the weather in a location',
225+
parameters: z.object({
226+
location: z.string().describe('The location to get the weather for'),
227+
}),
228+
execute: async ({ location }) => ({
229+
location,
230+
temperature: 72 + Math.floor(Math.random() * 21) - 10,
231+
}),
232+
},
233+
},
234+
prompt: 'What is the weather in San Francisco?',
235+
});
236+
237+
console.log(result.text);
238+
```
239+
240+
### With Image Input
241+
242+
```ts
243+
import { minimax } from '@ai-sdk/minimax';
244+
import { generateText } from 'ai';
245+
246+
const result = await generateText({
247+
model: minimax('MiniMax-M2'),
248+
messages: [
249+
{
250+
role: 'user',
251+
content: [
252+
{ type: 'text', text: 'What is in this image?' },
253+
{
254+
type: 'image',
255+
image: 'https://example.com/image.jpg',
256+
},
257+
],
258+
},
259+
],
260+
});
261+
262+
console.log(result.text);
263+
```
264+

packages/minimax/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['vercel-ai'],
4+
};
5+

packages/minimax/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dist
2+
node_modules
3+
*.tsbuildinfo
4+
.turbo
5+
.env
6+
.env.local
7+
.DS_Store
8+
coverage
9+
*.log

packages/minimax/.npmignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
src
2+
*.test.ts
3+
*.test.tsx
4+
__tests__
5+
__mocks__
6+
__fixtures__
7+
__snapshots__
8+
tsconfig.json
9+
tsconfig.build.json
10+
tsup.config.ts
11+
vitest.*.config.js
12+
turbo.json
13+
.eslintrc.js
14+
.gitignore
15+
.env
16+
.env.*
17+
*.tsbuildinfo
18+
.turbo
19+
coverage
20+
*.log
21+
22+
# Documentation that should not be in the package
23+
INSTALLATION.md
24+
PROJECT_OVERVIEW.md
25+
COMMUNITY_PROVIDER_SUBMISSION.md
26+
SUMMARY.md

packages/minimax/.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
...require('../../.prettierrc.js'),
3+
};
4+

packages/minimax/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# @ai-sdk/minimax
2+
3+
## 0.0.1
4+
5+
### Initial Release
6+
7+
- Added MiniMax provider with support for MiniMax-M2 text generation model
8+
- **Default provider**: Anthropic-compatible API via `minimax` and `createMinimax` exports
9+
- OpenAI-compatible API interface via `minimaxOpenAI` and `createMinimaxOpenAI` exports
10+
- Anthropic-compatible API interface via `minimaxAnthropic` export
11+
- Both compatibility modes included in a single package
12+
- Streaming and non-streaming text generation
13+
- Custom configuration support for both modes
14+
- Separate test files for each provider for better maintainability
15+
- Provider identifiers: `minimax.anthropic` and `minimax.openai`
16+

0 commit comments

Comments
 (0)