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), before any function runs. API_BASE = os.getenv('MINIMAX_API_BASE') is falsy, so merely importing minimax_tts (or running it) aborts. The script needs the base URL to pick the China-mainland (api.minimaxi.com/v1) vs overseas (api.minimax.io/v1) host for POST {API_BASE}/t2a_v2.

Source

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

  python minimax_tts.py "Hello world" -o output.mp3
  python minimax_tts.py "你好世界" -o hi.mp3 -v female-shaonv --model speech-2.8-hd
  python minimax_tts.py "Welcome" -o out.wav -v male-qn-jingying --speed 0.8 --format wav

Env: MINIMAX_API_KEY (required)
"""

import os
import sys
import json
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.")


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:

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Export the base URL for your region: `export MINIMAX_API_BASE='https://api.minimax.io/v1'` (overseas) or `https://api.minimaxi.com/v1` (China mainland).
  2. Ensure the var is set in the SAME process/shell before importing or running — since the check is at import time, setting it after import is too late.
  3. Add MINIMAX_API_BASE next to MINIMAX_API_KEY in your .env / CI secret injection.
  4. Verify with `python -c "import os;print(os.getenv('MINIMAX_API_BASE'))"` in the exact launch environment.

Example fix

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

// after
$ export MINIMAX_API_BASE='https://api.minimax.io/v1'
$ python minimax_tts.py "hi" -o out.mp3
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_tts")
# safe to import now that the module-level check will pass
import skills.frontend_dev.scripts.minimax_tts as tts_mod

Type guard

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

Try / catch

try:
    import minimax_tts  # triggers module-level API_BASE check
except SystemExit as e:
    if "MINIMAX_API_BASE" in str(e):
        os.environ["MINIMAX_API_BASE"] = "https://api.minimax.io/v1"
        raise EnvironmentError("set MINIMAX_API_BASE then re-import") from e
    raise

Prevention

When it happens

Trigger: Importing the module or running the CLI in any environment where MINIMAX_API_BASE is unset/empty. Because it is module-level, even `import minimax_tts` in another script triggers it — there is no chance to set the var after import.

Common situations: Only MINIMAX_API_KEY was exported but BASE was forgotten; a shared .env missing the base URL; CI secret config has the key but not the host; copy-pasting a snippet that imports the module without first sourcing env.

Related errors


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