Skip to content

feat: add image download and save support to ImageSDK#145

Open
NianJiuZst wants to merge 1 commit into
MiniMax-AI:mainfrom
NianJiuZst:feat/sdk-image-download
Open

feat: add image download and save support to ImageSDK#145
NianJiuZst wants to merge 1 commit into
MiniMax-AI:mainfrom
NianJiuZst:feat/sdk-image-download

Conversation

@NianJiuZst
Copy link
Copy Markdown
Contributor

Summary

Closes #144

Adds ImageSDK.save() — a method that downloads or decodes generated images to disk, matching the CLI's --out / --out-dir / --out-prefix behavior.

Motivation

ImageSDK.generate() returns URLs or base64 data, but leaves downloading and file I/O entirely to the user. Every SDK user who wants to save images must:

  1. Manually download from CDN URLs (with retries for reliability)
  2. Handle base64 decoding if using that response format
  3. Create output directories
  4. Implement filename generation

This is boilerplate that the CLI already handles. The SDK should too.

Usage

import { MiniMaxSDK } from 'mmx-cli/sdk';

const sdk = new MiniMaxSDK({ apiKey: 'sk-...' });

const result = await sdk.image.generate({
  prompt: 'A cat in a spacesuit',
  n: 3,
});

// Save to individual files in a directory
const paths = await sdk.image.save(result, {
  outDir: './generated',
  prefix: 'cat',
});
// → ['./generated/cat_001.jpg', './generated/cat_002.jpg', './generated/cat_003.jpg']

// Or save a single image to an exact path
await sdk.image.save(result, { out: '/tmp/avatar.png' });

Files changed

File Change
src/sdk/image/index.ts +51 lines — ImageSaveOptions interface + save() method
test/sdk/image.test.ts +85 lines — 4 test cases for base64 save, multi-file, out conflict

Screenshots

Add a `save()` method to ImageSDK that downloads generated images to
disk, matching the CLI's --out / --out-dir / --out-prefix behavior:

- save(response, { out }) — save single image to exact path
- save(response, { outDir, prefix? }) — save multiple images with
  auto-numbered filenames (image_001.jpg, image_002.jpg, ...)
- Handles both "url" (CDN download via downloadFile) and "base64"
  (direct decode) response formats
- Creates intermediate directories as needed
- Throws when `out` is used with multi-image responses

Also export the `ImageSaveOptions` interface for TypeScript users.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageSDK lacks image download/save capability

1 participant