MiniMax-AI/skills · critical · SystemExit
ERROR: MINIMAX_API_KEY is not set.\n export MINIMAX_API_KEY
Error message
ERROR: MINIMAX_API_KEY is not set.\n export MINIMAX_API_KEY='your-key'
What it means
Raised inside the _headers() helper, called lazily when generate_image() makes its POST. API_KEY is falsy so the Authorization Bearer header cannot be built. Because the check is in _headers (not at import), importing the module succeeds; it only fails when a request is attempted.
Source
Thrown at skills/gif-sticker-maker/scripts/minimax_image.py:33
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")
with open(image_path, "rb") as f:
raw = f.read()
return f"data:image/{mime};base64,{base64.b64encode(raw).decode()}"
def generate_image(
prompt: str,View on GitHub (pinned to 60aaae52bb)
Solutions
- Export the key: `export MINIMAX_API_KEY='your-key'` then re-run.
- Source .env before launching; confirm with `env | grep MINIMAX`.
- In CI, inject MINIMAX_API_KEY as a secret env on the step and assert non-empty up front.
Example fix
// before $ python minimax_image.py "a cat" -o cat.png ERROR: MINIMAX_API_KEY is not set. // after $ export MINIMAX_API_KEY='your-key' $ python minimax_image.py "a cat" -o cat.png
Defensive patterns
Strategy: validation
Validate before calling
import os
if not os.getenv("MINIMAX_API_KEY"):
raise EnvironmentError("MINIMAX_API_KEY must be set before calling generate_image()")
if not os.getenv("MINIMAX_API_BASE"):
raise EnvironmentError("MINIMAX_API_BASE must be set before importing minimax_image")
from skills.gif_sticker_maker.scripts.minimax_image import generate_image Type guard
def has_image_key() -> bool:
"""True only when the image API key env var is non-empty."""
return bool(os.getenv("MINIMAX_API_KEY")) Try / catch
import subprocess, sys
try:
subprocess.run([sys.executable, "minimax_image.py", prompt, "-o", out], check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
if "MINIMAX_API_KEY is not set" in (e.stderr or ""):
raise EnvironmentError("export MINIMAX_API_KEY first") from e
raise Prevention
- Assert both MINIMAX env vars in one bootstrap step before any image call.
- Gate CI steps on `test -n "$MINIMAX_API_KEY"`.
- Run `env | grep MINIMAX` as a preflight in the launching shell.
When it happens
Trigger: Calling generate_image() or running the CLI with MINIMAX_API_KEY unset/empty (while API_BASE was set so import succeeded).
Common situations: .env not sourced; CI secret empty/masked; different shell/subprocess than where the export ran; key var name typo; key set interactively but not in the runner subprocess.
Related errors
- ERROR: MINIMAX_API_KEY is not set. export MINIMAX_API_KEY=
- ERROR: MINIMAX_API_KEY is not set. export MINIMAX_API_KEY=
- ERROR: MINIMAX_API_KEY is not set. export MINIMAX_API_KEY=
- ERROR: MINIMAX_API_BASE is not set.
- ERROR: MINIMAX_API_BASE is not set.
AI-assisted analysis of MiniMax-AI/skills@60aaae52bb (2026-08-13).
Data as JSON: /api/errors/5d72569aa30f1f5a.
Report an issue: GitHub.