|
| 1 | +# MiniMax SDK |
| 2 | + |
| 3 | +TypeScript SDK for the [MiniMax](https://www.minimaxi.com) AI platform. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install mmx-cli |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { MiniMaxSDK } from 'mmx-cli/sdk'; |
| 15 | + |
| 16 | +const sdk = new MiniMaxSDK({ |
| 17 | + apiKey: 'sk-xxxxx', |
| 18 | + region: 'global', // or 'cn' |
| 19 | +}); |
| 20 | +``` |
| 21 | + |
| 22 | +You can also omit `apiKey` if it's already configured via `mmx config set api-key <key>`. |
| 23 | + |
| 24 | +## Modules |
| 25 | + |
| 26 | +### Text |
| 27 | + |
| 28 | +```typescript |
| 29 | +const response = await sdk.text.chat({ |
| 30 | + model: 'MiniMax-M2.7', |
| 31 | + messages: [{ role: 'user', content: 'Hello!' }], |
| 32 | + max_tokens: 4096, |
| 33 | +}); |
| 34 | + |
| 35 | +// Streaming |
| 36 | +const stream = await sdk.text.chat({ |
| 37 | + model: 'MiniMax-M2.7', |
| 38 | + messages: [{ role: 'user', content: 'Write a poem' }], |
| 39 | + stream: true, |
| 40 | +}); |
| 41 | + |
| 42 | +for await (const event of stream) { |
| 43 | + console.log(event.choices[0]?.delta?.content); |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### Image |
| 48 | + |
| 49 | +```typescript |
| 50 | +const result = await sdk.image.generate({ |
| 51 | + model: 'image-01', |
| 52 | + prompt: 'A cat in a spacesuit', |
| 53 | + width: 1024, |
| 54 | + height: 1024, |
| 55 | + n: 1, |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +### Video |
| 60 | + |
| 61 | +```typescript |
| 62 | +// Synchronous — waits for completion |
| 63 | +const video = await sdk.video.generate({ |
| 64 | + model: 'MiniMax-Hailuo-2.3', |
| 65 | + prompt: 'Ocean waves at sunset', |
| 66 | +}); |
| 67 | + |
| 68 | +// Asynchronous — returns task ID immediately |
| 69 | +const { taskId } = await sdk.video.generate({ |
| 70 | + prompt: 'A robot painting', |
| 71 | + async: true, |
| 72 | +}); |
| 73 | + |
| 74 | +const task = await sdk.video.getTask({ taskId }); |
| 75 | + |
| 76 | +// Download |
| 77 | +const { size, save, downloadUrl } = await sdk.video.download({ |
| 78 | + fileId: '176844028768320', |
| 79 | + outPath: './video.mp4', |
| 80 | +}); |
| 81 | +``` |
| 82 | + |
| 83 | +### Speech |
| 84 | + |
| 85 | +```typescript |
| 86 | +const speech = await sdk.speech.synthesize({ |
| 87 | + model: 'speech-2.8-hd', |
| 88 | + text: 'Hello, world!', |
| 89 | + voice_setting: { voice_id: 'English_expressive_narrator' }, |
| 90 | + audio_setting: { format: 'mp3', sample_rate: 32000, bitrate: 128000, channel: 1 }, |
| 91 | +}); |
| 92 | + |
| 93 | +// Streaming |
| 94 | +const stream = await sdk.speech.synthesize({ |
| 95 | + text: 'Stream me', |
| 96 | + stream: true, |
| 97 | +}); |
| 98 | + |
| 99 | +for await (const chunk of stream) { |
| 100 | + // process audio chunks |
| 101 | +} |
| 102 | + |
| 103 | +// List voices |
| 104 | +const voices = await sdk.speech.voices(); |
| 105 | +const englishVoices = await sdk.speech.voices('en'); |
| 106 | +``` |
| 107 | + |
| 108 | +### Music |
| 109 | + |
| 110 | +```typescript |
| 111 | +const music = await sdk.music.generate({ |
| 112 | + model: 'music-2.6', |
| 113 | + prompt: 'Upbeat pop song', |
| 114 | + lyrics: '[verse] La da dee, sunny day', |
| 115 | + output_format: 'hex', |
| 116 | +}); |
| 117 | + |
| 118 | +// Instrumental |
| 119 | +const instrumental = await sdk.music.generate({ |
| 120 | + prompt: 'Cinematic orchestral', |
| 121 | + instrumental: true, |
| 122 | +}); |
| 123 | + |
| 124 | +// Auto-generate lyrics |
| 125 | +const autoLyrics = await sdk.music.generate({ |
| 126 | + prompt: 'Indie folk, melancholic, rainy night', |
| 127 | + lyrics_optimizer: true, |
| 128 | +}); |
| 129 | + |
| 130 | +// Streaming |
| 131 | +const stream = await sdk.music.generate({ |
| 132 | + prompt: 'Upbeat pop', |
| 133 | + lyrics: '[verse] Hello world', |
| 134 | + stream: true, |
| 135 | +}); |
| 136 | + |
| 137 | +for await (const chunk of stream) { |
| 138 | + // process audio chunks |
| 139 | +} |
| 140 | + |
| 141 | +// Structured prompt |
| 142 | +const structured = await sdk.music.generate({ |
| 143 | + prompt: 'A beautiful song', |
| 144 | + vocals: 'warm male baritone', |
| 145 | + genre: 'jazz', |
| 146 | + mood: 'relaxing', |
| 147 | + instruments: 'piano, saxophone', |
| 148 | + bpm: 120, |
| 149 | + key: 'C major', |
| 150 | +}); |
| 151 | +``` |
| 152 | + |
| 153 | +### Vision |
| 154 | + |
| 155 | +```typescript |
| 156 | +const result = await sdk.vision.describe({ |
| 157 | + image: 'https://example.com/photo.jpg', |
| 158 | + prompt: 'What breed is this dog?', |
| 159 | +}); |
| 160 | + |
| 161 | +console.log(result.content); |
| 162 | +``` |
| 163 | + |
| 164 | +### Search |
| 165 | + |
| 166 | +```typescript |
| 167 | +const results = await sdk.search.query('MiniMax AI latest news'); |
| 168 | + |
| 169 | +for (const item of results.organic) { |
| 170 | + console.log(item.title, item.link, item.snippet); |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +### Quota |
| 175 | + |
| 176 | +```typescript |
| 177 | +const quota = await sdk.quota.info(); |
| 178 | +console.log(quota); |
| 179 | +``` |
| 180 | + |
| 181 | +## Custom Base URL |
| 182 | + |
| 183 | +```typescript |
| 184 | +const sdk = new MiniMaxSDK({ |
| 185 | + apiKey: 'sk-xxxxx', |
| 186 | + baseUrl: 'https://api.minimax.io', |
| 187 | +}); |
| 188 | +``` |
0 commit comments