MiniMax-AI/skills · critical · SystemExit

ERROR: MINIMAX_API_KEY is not set. export MINIMAX_API_KEY=

Error message

ERROR: MINIMAX_API_KEY is not set.
  export MINIMAX_API_KEY='your-key'

What it means

Raised inside tts() (lazy, not at import) when API_KEY is falsy. Unlike the API_BASE check, this fires only when you actually call the function or run the CLI, so importing the module is safe. Without the key the script cannot build the Authorization Bearer header for POST {API_BASE}/t2a_v2.

Source

Thrown at skills/frontend-dev/scripts/minimax_tts.py:45


def tts(
    text: str,
    voice_id: str = "male-qn-qingse",
    model: str = "speech-2.8-hd",
    speed: float = 1.0,
    volume: float = 1.0,
    pitch: int = 0,
    emotion: str = "",
    sample_rate: int = 32000,
    bitrate: int = 128000,
    fmt: str = "mp3",
    language_boost: str = "auto",
    timeout: int = 120,
) -> bytes:
    """Synchronous HTTP TTS. Returns raw audio bytes."""
    if not API_KEY:
        raise SystemExit("ERROR: MINIMAX_API_KEY is not set.\n  export MINIMAX_API_KEY='your-key'")

    voice_setting = {"voice_id": voice_id, "speed": speed, "vol": volume, "pitch": pitch}
    if emotion:
        voice_setting["emotion"] = emotion

    payload = {
        "model": model,
        "text": text,
        "stream": False,
        "voice_setting": voice_setting,
        "audio_setting": {
            "sample_rate": sample_rate,
            "bitrate": bitrate,
            "format": fmt,
            "channel": 1,
        },
        "language_boost": language_boost,
        "output_format": "hex",

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Export the key: `export MINIMAX_API_KEY='your-key'` then re-run.
  2. Source your .env (`set -a; source .env; set +a`) since the script does not auto-load dotenv.
  3. Confirm both vars together: `env | grep MINIMAX` should show non-empty KEY and BASE.
  4. For CI, set MINIMAX_API_KEY as a secret env on the step and fail fast if empty.

Example fix

// before
$ python minimax_tts.py "hello" -o out.mp3
ERROR: MINIMAX_API_KEY is not set.

// after
$ export MINIMAX_API_KEY='your-key'
$ python minimax_tts.py "hello" -o out.mp3
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 tts()")
if not os.getenv("MINIMAX_API_BASE"):
    raise EnvironmentError("MINIMAX_API_BASE must be set before importing minimax_tts")
from skills.frontend_dev.scripts.minimax_tts import tts

Type guard

def has_tts_key() -> bool:
    """True only when the TTS key env var is non-empty."""
    return bool(os.getenv("MINIMAX_API_KEY"))

Try / catch

import subprocess, sys
try:
    subprocess.run([sys.executable, "minimax_tts.py", text, "-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

When it happens

Trigger: Calling tts() or running `python minimax_tts.py "text" -o out.mp3` with MINIMAX_API_KEY unset/empty. Possible because the BASE check passed (import succeeded) but the key was never set.

Common situations: .env not sourced; key injected in CI but masked/empty; different shell/subprocess than where the export was done; variable name typo; key present in interactive shell but not in the runner that spawned the script.

Related errors


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