Skip to content

fix: force HTTPS for image downloads and add base64 response format#94

Open
nguyenngothuong wants to merge 1 commit intoMiniMax-AI:mainfrom
nguyenngothuong:fix/image-download-https
Open

fix: force HTTPS for image downloads and add base64 response format#94
nguyenngothuong wants to merge 1 commit intoMiniMax-AI:mainfrom
nguyenngothuong:fix/image-download-https

Conversation

@nguyenngothuong
Copy link
Copy Markdown

Problem

The mmx image generate command fails with Network request failed when trying to download generated images from certain regions (confirmed from Vietnam, likely affects others).

Root Cause

The MiniMax Image Generation API returns image URLs using HTTP (e.g. http://hailuo-image-*.oss-us-east-1.aliyuncs.com/...), but the Alibaba Cloud OSS US East CDN blocks HTTP traffic, causing fetch() to fail.

❌ http://hailuo-image-*.oss-us-east-1.aliyuncs.com/... → "fetch failed"
✅ https://hailuo-image-*.oss-us-east-1.aliyuncs.com/... → 200 OK

Solution

1. Force HTTPS in download.ts

Auto-convert http://https:// before fetching, with retry logic (3 attempts, exponential backoff).

2. Add --response-format base64 flag

The API supports response_format: base64 which returns base64-encoded images directly, completely bypassing the CDN download step. This is useful as a fallback when CDN URLs are unreachable.

Changes

File Description
src/files/download.ts Force HTTPS conversion + retry logic
src/commands/image/generate.ts Add `--response-format <url
src/types/api.ts Add response_format and image_base64 types

Test Results

# Default mode (HTTP→HTTPS fix)
mmx image "A sunset over mountains" --out-dir ./out/
# ✅ Saved: ./out/image_001.jpg (290KB, 1024x1024 JPEG)

# Base64 mode (bypasses CDN entirely)
mmx image "A cat wearing sunglasses" --response-format base64 --out-dir ./out/
# ✅ Saved: ./out/image_001.jpg (571KB, 1024x1024 JPEG)

Related

- Auto-convert HTTP to HTTPS in downloadFile() to work around
  Alibaba Cloud OSS CDN blocking HTTP traffic from certain regions
- Add --response-format <url|base64> flag for image generation
- Add retry logic (3 attempts, exponential backoff) for download failures
- Fixes image download failures with 'Network request failed' error

Related: MiniMax API returns http:// URLs but OSS CDN requires https://
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.

1 participant