MiniMax-AI/skills · critical · SystemExit

ERROR: MINIMAX_API_BASE is not set.

Error message

ERROR: MINIMAX_API_BASE is not set.

What it means

Fires at MODULE IMPORT TIME (top-level line 26). API_BASE is falsy, so importing minimax_image or running the CLI aborts before any function runs. The base URL selects the China-mainland vs overseas host used for POST {API_BASE}/image_generation.

Source

Thrown at skills/gif-sticker-maker/scripts/minimax_image.py:26

  python3 minimax_image.py "Mountain landscape" -o bg.png --ratio 16:9
  python3 minimax_image.py "Funko Pop figurine waving" -o sticker.png --subject-ref photo.jpg

Env: MINIMAX_API_KEY (required)
"""

import os
import sys
import json
import base64
import argparse
import requests

API_KEY = os.getenv("MINIMAX_API_KEY")
# China Mainland: https://api.minimaxi.com/v1
# Overseas:       https://api.minimax.io/v1
API_BASE = os.getenv("MINIMAX_API_BASE")
if not API_BASE:
    raise SystemExit("ERROR: MINIMAX_API_BASE is not set.")

ASPECT_RATIOS = ["1:1", "16:9", "4:3", "3:2", "2:3", "3:4", "9:16", "21:9"]


def _headers():
    if not API_KEY:
        raise SystemExit("ERROR: MINIMAX_API_KEY is not set.\n  export MINIMAX_API_KEY='your-key'")
    return {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    }


def _encode_image(image_path: str) -> str:
    """Read local image file and return base64 data URI."""
    ext = os.path.splitext(image_path)[1].lower().lstrip(".")
    mime_map = {"jpg": "jpeg", "jpeg": "jpeg", "png": "png", "webp": "webp"}
    mime = mime_map.get(ext, "jpeg")

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Export the region host: `export MINIMAX_API_BASE='https://api.minimax.io/v1'` (overseas) or `https://api.minimaxi.com/v1` (China mainland).
  2. Set it in the same process before import/run; add it to .env and CI secrets next to the key.
  3. Verify: `python -c "import os;print(os.getenv('MINIMAX_API_BASE'))"` in the launch environment.

Example fix

// before
$ python minimax_image.py "a cat" -o cat.png
ERROR: MINIMAX_API_BASE is not set.

// after
$ export MINIMAX_API_BASE='https://api.minimax.io/v1'
$ python minimax_image.py "a cat" -o cat.png
Defensive patterns

Strategy: validation

Validate before calling

import os

base = os.getenv("MINIMAX_API_BASE")
if not base:
    raise EnvironmentError("MINIMAX_API_BASE must be set BEFORE importing minimax_image")
import skills.gif_sticker_maker.scripts.minimax_image as image_mod

Type guard

def image_env_ready() -> bool:
    """True only when the import-time API_BASE requirement is satisfied."""
    return bool(os.getenv("MINIMAX_API_BASE"))

Try / catch

try:
    import minimax_image  # module-level API_BASE check
except SystemExit as e:
    if "MINIMAX_API_BASE" in str(e):
        raise EnvironmentError("set MINIMAX_API_BASE before importing minimax_image") from e
    raise

Prevention

When it happens

Trigger: Importing the module or running the CLI with MINIMAX_API_BASE unset/empty. Because it is module-level, `import minimax_image` alone triggers it; setting the var after import is too late.

Common situations: Only the API key exported; .env missing the base URL; CI has the key but not the host; importing the module from another script before sourcing env.

Related errors


AI-assisted analysis of MiniMax-AI/skills@60aaae52bb (2026-08-13). Data as JSON: /api/errors/c70aee10d3111163. Report an issue: GitHub.