@cogito.ai/minimax
v0.2.0
Published
Typed, testable MiniMax media-generation client (image / music / video) with byte-only outputs and a duck-typed error classifier
Readme
@cogito.ai/minimax
A typed, testable wrapper around MiniMax's media-generation capabilities
(image, music, video), built on top of mmx-cli's undocumented SDK export
(mmx-cli/sdk).
Why this exists
mmx-cli (github.com/MiniMax-AI/cli) is the only MiniMax SDK on npm, but:
- It has no README and no doc comments on its public surface.
- Its capability set is not stable across patch releases —
musicwas removed from the SDK between1.0.19and1.0.21without a major version bump, even though MiniMax'smusic_generationHTTP endpoint is still live. - Its media-generation methods hand back MiniMax's own CDN URLs, which expire quickly (image/music: 24h; video: as little as 1h).
This package wraps mmx-cli/sdk behind a narrow, hand-declared interface
(MinimaxClient) instead of trusting the SDK's own types as a contract, so
that a future capability removal fails loudly at tsc time instead of
silently at runtime — see src/client.ts's doc comment and
src/client.test.ts's type-level sentinel test. Every generation function
downloads or decodes bytes itself and returns a Buffer; none of them ever
hand a MiniMax URL back to the caller.
mmx-cli is pinned to an exact version (no ^) for the reason above.
API
createMinimaxClient(opts)— wrapsnew MiniMaxSDK(...)for image, video, file, and quota calls.generateImage(client, params)— always requestsresponse_format: "base64"; returns oneGeneratedAssetper candidate, with content-type sniffed from the bytes' magic numbers (MiniMax's API has no output-format parameter).createMinimaxMusicClient(opts)/generateMusic(client, params)— music generation bypassesmmx-cli/sdkentirely (removed as of1.0.21) and calls MiniMax'smusic_generationendpoint directly. Always forcesis_instrumental: true— this package has nolyricsparameter, and MiniMax's API requires one oflyrics/is_instrumental/lyrics_optimizer.generateVideoScarce(client, params, options?)— named for its scarcity: MiniMax caps video at 3 requests/day and excludes it from the Token Plan. This function never retries automatically on any failure (generation, polling, or download). It pollsvideo.getTaskuntil the task leavesQueueing/Processing, then downloads the result to aBufferimmediately after resolving a short-liveddownload_url.classifyError(err)— duck-types.exitCode(mirroringmmx-cli's own unexportedExitCodeenum) into a stable category string. Works for errors from both the SDK-backed and the raw-HTTP-backed (music) paths.getQuota(client)/isQuotaExhausted(quota, modelName)/msUntilReset(quota, modelName)— quota helpers for deciding whether to wait out a rate limit instead of guessing.
Configuration
This package never reads environment variables. Every function takes its configuration (API key, base URL) as an explicit argument, injected by the caller.
