Skip to content

Commit f76a84d

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

20 files changed

+993
-0
lines changed

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+

packages/minimax/README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# AI SDK - MiniMax Provider
2+
3+
The **[MiniMax provider](https://ai-sdk.dev/providers/ai-sdk-providers/minimax)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [MiniMax](https://www.minimaxi.com) platform.
4+
5+
## Setup
6+
7+
The MiniMax provider is available in the `@ai-sdk/minimax` module. You can install it with
8+
9+
```bash
10+
npm i @ai-sdk/minimax
11+
```
12+
13+
## Provider Instance
14+
15+
You can import the default provider instance `minimax` from `@ai-sdk/minimax`:
16+
17+
```ts
18+
import { minimax } from '@ai-sdk/minimax';
19+
```
20+
21+
> **Note**: The default `minimax` instance uses the Anthropic-compatible API format, which provides better support for advanced features. If you need the OpenAI-compatible format, use `minimaxOpenAI` instead.
22+
23+
## Example
24+
25+
```ts
26+
import { minimax } from '@ai-sdk/minimax';
27+
import { generateText } from 'ai';
28+
29+
const { text } = await generateText({
30+
model: minimax('MiniMax-M2'),
31+
prompt: 'Write a JavaScript function that sorts a list:',
32+
});
33+
```
34+
35+
## API Compatibility
36+
37+
MiniMax provides two API compatibility modes, both included in this package:
38+
39+
### Anthropic-Compatible API (Default)
40+
41+
```ts
42+
import { minimax } from '@ai-sdk/minimax';
43+
import { generateText } from 'ai';
44+
45+
const { text } = await generateText({
46+
model: minimax('MiniMax-M2'),
47+
prompt: 'Hello!',
48+
});
49+
```
50+
51+
Or explicitly:
52+
53+
```ts
54+
import { minimaxAnthropic } from '@ai-sdk/minimax';
55+
import { generateText } from 'ai';
56+
57+
const { text } = await generateText({
58+
model: minimaxAnthropic('MiniMax-M2'),
59+
prompt: 'Hello!',
60+
});
61+
```
62+
63+
### OpenAI-Compatible API
64+
65+
```ts
66+
import { minimaxOpenAI } from '@ai-sdk/minimax';
67+
import { generateText } from 'ai';
68+
69+
const { text } = await generateText({
70+
model: minimaxOpenAI('MiniMax-M2'),
71+
prompt: 'Hello!',
72+
});
73+
```
74+
75+
### Custom Configuration
76+
77+
You can create custom provider instances with specific settings:
78+
79+
```ts
80+
import { createMinimax, createMinimaxOpenAI } from '@ai-sdk/minimax';
81+
82+
// Anthropic-compatible with custom settings (default)
83+
const customAnthropic = createMinimax({
84+
apiKey: process.env.MINIMAX_API_KEY,
85+
baseURL: 'https://api.minimax.io/anthropic/v1', // optional, this is the default
86+
headers: {
87+
'Custom-Header': 'value',
88+
},
89+
});
90+
91+
// OpenAI-compatible with custom settings
92+
const customOpenAI = createMinimaxOpenAI({
93+
apiKey: process.env.MINIMAX_API_KEY,
94+
baseURL: 'https://api.minimax.io/v1', // optional, this is the default
95+
headers: {
96+
'Custom-Header': 'value',
97+
},
98+
});
99+
```
100+
101+
## Configuration Options
102+
103+
Both `createMinimax` (Anthropic-compatible) and `createMinimaxOpenAI` (OpenAI-compatible) accept the following options:
104+
105+
- **apiKey** _string_
106+
107+
API key for authenticating with the MiniMax API. Defaults to the `MINIMAX_API_KEY` environment variable.
108+
109+
- **baseURL** _string_
110+
111+
Custom base URL for API calls.
112+
- Anthropic-compatible default: `https://api.minimax.io/anthropic/v1`
113+
- OpenAI-compatible default: `https://api.minimax.io/v1`
114+
115+
- **headers** _Record<string, string>_
116+
117+
Custom headers to include in API requests.
118+
119+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
120+
121+
Custom fetch implementation for intercepting requests or testing.
122+
123+
## Streaming Example
124+
125+
```ts
126+
import { minimax } from '@ai-sdk/minimax';
127+
import { streamText } from 'ai';
128+
129+
const result = streamText({
130+
model: minimax('MiniMax-M2'),
131+
prompt: 'Write a short story about a robot.',
132+
});
133+
134+
for await (const chunk of result.textStream) {
135+
process.stdout.write(chunk);
136+
}
137+
```
138+
139+
## Exports
140+
141+
This package exports the following:
142+
143+
- **Functions**:
144+
- `createMinimax` (Anthropic-compatible, default)
145+
- `minimax` (Anthropic-compatible, default)
146+
- `minimaxAnthropic` (Anthropic-compatible)
147+
- `createMinimaxOpenAI` (OpenAI-compatible)
148+
- `minimaxOpenAI` (OpenAI-compatible)
149+
- **Types**:
150+
- `MinimaxProvider` (Anthropic-compatible)
151+
- `MinimaxProviderSettings` (Anthropic-compatible)
152+
- `MinimaxAnthropicProvider`
153+
- `MinimaxAnthropicProviderSettings`
154+
- `MinimaxOpenAIProvider`
155+
- `MinimaxOpenAIProviderSettings`
156+
- `MinimaxErrorData`
157+
158+
## Documentation
159+
160+
Please check out the **[MiniMax provider](https://ai-sdk.dev/providers/ai-sdk-providers/minimax)** for more information.
161+

packages/minimax/package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "@ai-sdk/minimax",
3+
"version": "0.0.1",
4+
"license": "Apache-2.0",
5+
"sideEffects": false,
6+
"main": "./dist/index.js",
7+
"module": "./dist/index.mjs",
8+
"types": "./dist/index.d.ts",
9+
"files": [
10+
"dist/**/*",
11+
"CHANGELOG.md"
12+
],
13+
"scripts": {
14+
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
15+
"build:watch": "pnpm clean && tsup --watch",
16+
"clean": "rm -rf dist *.tsbuildinfo",
17+
"lint": "eslint \"./**/*.ts*\"",
18+
"type-check": "tsc --build",
19+
"prettier-check": "prettier --check \"./**/*.ts*\"",
20+
"test": "pnpm test:node && pnpm test:edge",
21+
"test:update": "pnpm test:node -u",
22+
"test:watch": "vitest --config vitest.node.config.js",
23+
"test:edge": "vitest --config vitest.edge.config.js --run",
24+
"test:node": "vitest --config vitest.node.config.js --run"
25+
},
26+
"exports": {
27+
"./package.json": "./package.json",
28+
".": {
29+
"types": "./dist/index.d.ts",
30+
"import": "./dist/index.mjs",
31+
"require": "./dist/index.js"
32+
}
33+
},
34+
"dependencies": {
35+
"@ai-sdk/anthropic": "workspace:*",
36+
"@ai-sdk/openai-compatible": "workspace:*",
37+
"@ai-sdk/provider": "workspace:*",
38+
"@ai-sdk/provider-utils": "workspace:*"
39+
},
40+
"devDependencies": {
41+
"@types/node": "20.17.24",
42+
"@vercel/ai-tsconfig": "workspace:*",
43+
"tsup": "^8",
44+
"typescript": "5.8.3",
45+
"zod": "3.25.76"
46+
},
47+
"peerDependencies": {
48+
"zod": "^3.25.76 || ^4.1.8"
49+
},
50+
"engines": {
51+
"node": ">=18"
52+
},
53+
"publishConfig": {
54+
"access": "public"
55+
},
56+
"homepage": "https://ai-sdk.dev/docs",
57+
"repository": {
58+
"type": "git",
59+
"url": "git+https://github.com/vercel/ai.git"
60+
},
61+
"bugs": {
62+
"url": "https://github.com/vercel/ai/issues"
63+
},
64+
"keywords": [
65+
"ai",
66+
"minimax"
67+
]
68+
}
69+

packages/minimax/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Anthropic-compatible API (Default)
2+
export {
3+
createMinimaxAnthropic as createMinimax,
4+
minimaxAnthropic as minimax,
5+
minimaxAnthropic,
6+
} from './minimax-anthropic-provider';
7+
8+
export type {
9+
MinimaxAnthropicProvider as MinimaxProvider,
10+
MinimaxAnthropicProviderSettings as MinimaxProviderSettings,
11+
MinimaxAnthropicProvider,
12+
MinimaxAnthropicProviderSettings,
13+
} from './minimax-anthropic-provider';
14+
15+
// OpenAI-compatible API
16+
export {
17+
createMinimax as createMinimaxOpenAI,
18+
minimaxOpenAI,
19+
} from './minimax-openai-provider';
20+
21+
export type {
22+
MinimaxProvider as MinimaxOpenAIProvider,
23+
MinimaxProviderSettings as MinimaxOpenAIProviderSettings,
24+
} from './minimax-openai-provider';
25+
26+
// Common exports
27+
export type { OpenAICompatibleErrorData as MinimaxErrorData } from '@ai-sdk/openai-compatible';
28+
export { VERSION } from './version';
29+

0 commit comments

Comments
 (0)