MiniMax-AI/skills · error · SystemExit

API Error [{base_resp.get('status_code')}]: {base_resp.get('

Error message

API Error [{base_resp.get('status_code')}]: {base_resp.get('status_msg')}

What it means

`raise SystemExit(f"API Error [{status_code}]: {status_msg}")` in `generate_image` after the MiniMax `image_generation` endpoint returns a 2xx HTTP response whose JSON body's `base_resp.status_code` is non-zero. MiniMax signals application-level errors (as opposed to HTTP errors) inside a 200 response via `base_resp`; a non-zero status indicates the request was received but rejected for a business reason. The message prints both the numeric code and the API's status message for diagnosis.

Source

Thrown at skills/frontend-dev/scripts/minimax_image.py:71

        "n": n,
        "response_format": response_format,
        "prompt_optimizer": prompt_optimizer,
    }
    if seed is not None:
        payload["seed"] = seed

    resp = requests.post(
        f"{API_BASE}/image_generation",
        headers=_headers(),
        json=payload,
        timeout=120,
    )
    resp.raise_for_status()
    data = resp.json()

    base_resp = data.get("base_resp", {})
    if base_resp.get("status_code", 0) != 0:
        raise SystemExit(f"API Error [{base_resp.get('status_code')}]: {base_resp.get('status_msg')}")

    return data


def download_and_save(url: str, output_path: str):
    """Download image from URL and save."""
    resp = requests.get(url, timeout=60)
    resp.raise_for_status()
    with open(output_path, "wb") as f:
        f.write(resp.content)
    return len(resp.content)


def main():
    p = argparse.ArgumentParser(description="MiniMax Text-to-Image")
    p.add_argument("prompt", help="Image description (max 1500 chars)")
    p.add_argument("-o", "--output", required=True, help="Output file path (.png/.jpg)")
    p.add_argument("--model", default="image-01", help="Model (default: image-01)")

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Read the numeric code and `status_msg`: 1001x → auth/key/permission (verify key and region match the base URL); 1027/1039 → content policy — revise the prompt; 1xxx rate/quota — back off and retry.
  2. Confirm the key's region matches `MINIMAX_API_BASE` (overseas `api.minimax.io` keys vs China `api.minimaxi.com` keys are not interchangeable).
  3. Validate `aspect_ratio` is one of the allowed values and `model`/`n` are correct before sending.
  4. For rate/quota errors, implement exponential backoff and retry the same idempotent request.

Example fix

# before — overseas key + China base URL (region mismatch)
export MINIMAX_API_BASE='https://api.minimaxi.com/v1'  # China
export MINIMAX_API_KEY='overseas-key'
# -> SystemExit: API Error [1004]: ... auth failure

# after — align regions
export MINIMAX_API_BASE='https://api.minimax.io/v1'   # overseas
export MINIMAX_API_KEY='overseas-key'
Defensive patterns

Strategy: retry

Validate before calling

def is_retryable(status_code: int) -> bool:
    # MiniMax rate-limit / quota / transient codes -> safe to back off and retry
    return status_code in {1027, 1039, 1008, 1009} or 1000 <= status_code < 1100 and status_code not in {1004, 1005}

# before sending
if aspect_ratio not in ASPECT_RATIOS:
    raise ValueError(f"aspect_ratio must be one of {ASPECT_RATIOS}")

Type guard

def is_auth_error(base_resp: dict) -> bool:
    code = base_resp.get("status_code", 0)
    return code in (1004, 1005, 1027)  # key/permission/auth-region errors

Try / catch

import time
for attempt in range(4):
    try:
        return generate_image(prompt, **kwargs)
    except SystemExit as e:
        if is_retryable(extract_code(e)) and attempt < 3:
            time.sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: Valid HTTP response (passed `raise_for_status`) but `base_resp.status_code != 0`. Common MiniMax status codes include authentication/permission failures, invalid model name, prompt-policy violations (content moderation), rate limiting, quota exhaustion, or an invalid `aspect_ratio`/`n` payload value.

Common situations: Wrong/region-mismatched API key (overseas key against China base URL or vice versa), an invalid `model` value, a prompt that trips content moderation, exceeded quota/rate limit, or a malformed `aspect_ratio` not in the allowed list.

Related errors


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