mirror of
https://github.com/MiniMax-AI/cli.git
synced 2026-09-18 08:48:06 +08:00
3.6 KiB
3.6 KiB
MiniMax SDK
TypeScript SDK for the MiniMax AI platform.
Installation
npm install mmx-cli
Quick Start
import { MiniMaxSDK } from 'mmx-cli/sdk';
const sdk = new MiniMaxSDK({
apiKey: 'sk-xxxxx',
region: 'global', // or 'cn'
});
You can also omit apiKey if it's already configured via mmx config set api-key <key>.
Modules
Text
const response = await sdk.text.chat({
model: 'MiniMax-M3',
messages: [{ role: 'user', content: 'Hello!' }],
max_tokens: 4096,
});
// Streaming
const stream = await sdk.text.chat({
model: 'MiniMax-M3',
messages: [{ role: 'user', content: 'Write a poem' }],
stream: true,
});
for await (const event of stream) {
console.log(event.choices[0]?.delta?.content);
}
Image
const result = await sdk.image.generate({
model: 'image-01',
prompt: 'A cat in a spacesuit',
width: 1024,
height: 1024,
n: 1,
});
Video
// Synchronous — waits for completion
const video = await sdk.video.generate({
model: 'MiniMax-Hailuo-2.3',
prompt: 'Ocean waves at sunset',
});
// MiniMax-H3 — Video Generation V2 with request defaults
const h3Video = await sdk.video.generate({
model: 'MiniMax-H3',
prompt: 'Ocean waves at sunset',
});
// Asynchronous — returns task ID immediately
const { taskId } = await sdk.video.generate({
prompt: 'A robot painting',
async: true,
});
const { taskId: h3TaskId } = await sdk.video.generate({
model: 'MiniMax-H3',
prompt: 'Ocean waves at sunset',
async: true,
});
const h3Task = await sdk.video.getTask({
taskId: h3TaskId,
model: 'MiniMax-H3',
});
const task = await sdk.video.getTask({ taskId });
// Download
const { size, save, downloadUrl } = await sdk.video.download({
fileId: '176844028768320',
outPath: './video.mp4',
});
Speech
const speech = await sdk.speech.synthesize({
model: 'speech-2.8-hd',
text: 'Hello, world!',
voice_setting: { voice_id: 'English_expressive_narrator' },
audio_setting: { format: 'mp3', sample_rate: 32000, bitrate: 128000, channel: 1 },
});
// Streaming
const stream = await sdk.speech.synthesize({
text: 'Stream me',
stream: true,
});
for await (const chunk of stream) {
// process audio chunks
}
// List voices
const voices = await sdk.speech.voices();
const englishVoices = await sdk.speech.voices('en');
Vision
const result = await sdk.vision.describe({
image: 'https://example.com/photo.jpg',
prompt: 'What breed is this dog?',
});
console.log(result.content);
Search
const results = await sdk.search.query('MiniMax AI latest news');
for (const item of results.organic) {
console.log(item.title, item.link, item.snippet);
}
The underlying
/v1/coding_plan/searchAPI returns at most 10 results per call and does not currently expose a pagination parameter (see #107). Refine your query if you need different results.
Quota
import {
isAccountBalanceResponse,
isQuotaResponse,
} from 'mmx-cli/sdk';
const quota = await sdk.quota.info();
if (isQuotaResponse(quota)) {
console.log(quota.model_remains);
} else if (isAccountBalanceResponse(quota)) {
console.log(quota.available_amount);
}
Token Plan credentials and OAuth return QuotaResponse. API secret keys with
the sk-api- prefix return AccountBalanceResponse. The type guards above
narrow the QuotaInfoResponse union without changing the raw API response.
Custom Base URL
const sdk = new MiniMaxSDK({
apiKey: 'sk-xxxxx',
baseUrl: 'https://api.minimax.io',
});