{"record":{"id":"22c123c10f4fbe95","repo":"MiniMax-AI/skills","slug":"error-minimax-api-base-is-not-set-22c123","errorCode":null,"errorMessage":"ERROR: MINIMAX_API_BASE is not set.","messagePattern":"ERROR: MINIMAX_API_BASE is not set\\.","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"critical","filePath":"skills/frontend-dev/scripts/minimax_tts.py","lineNumber":26,"sourceCode":"  python minimax_tts.py \"Hello world\" -o output.mp3\n  python minimax_tts.py \"你好世界\" -o hi.mp3 -v female-shaonv --model speech-2.8-hd\n  python minimax_tts.py \"Welcome\" -o out.wav -v male-qn-jingying --speed 0.8 --format wav\n\nEnv: MINIMAX_API_KEY (required)\n\"\"\"\n\nimport os\nimport sys\nimport json\nimport argparse\nimport requests\n\nAPI_KEY = os.getenv(\"MINIMAX_API_KEY\")\n# China Mainland: https://api.minimaxi.com/v1\n# Overseas:       https://api.minimax.io/v1\nAPI_BASE = os.getenv(\"MINIMAX_API_BASE\")\nif not API_BASE:\n    raise SystemExit(\"ERROR: MINIMAX_API_BASE is not set.\")\n\n\ndef tts(\n    text: str,\n    voice_id: str = \"male-qn-qingse\",\n    model: str = \"speech-2.8-hd\",\n    speed: float = 1.0,\n    volume: float = 1.0,\n    pitch: int = 0,\n    emotion: str = \"\",\n    sample_rate: int = 32000,\n    bitrate: int = 128000,\n    fmt: str = \"mp3\",\n    language_boost: str = \"auto\",\n    timeout: int = 120,\n) -> bytes:\n    \"\"\"Synchronous HTTP TTS. Returns raw audio bytes.\"\"\"\n    if not API_KEY:","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_tts.py#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","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.","Add MINIMAX_API_BASE next to MINIMAX_API_KEY in your .env / CI secret injection.","Verify with `python -c \"import os;print(os.getenv('MINIMAX_API_BASE'))\"` in the exact launch environment."],"exampleFix":"// before\n$ python minimax_tts.py \"hi\" -o out.mp3\nERROR: MINIMAX_API_BASE is not set.\n\n// after\n$ export MINIMAX_API_BASE='https://api.minimax.io/v1'\n$ python minimax_tts.py \"hi\" -o out.mp3","handlingStrategy":"validation","validationCode":"import os\n\nbase = os.getenv(\"MINIMAX_API_BASE\")\nif not base:\n    raise EnvironmentError(\"MINIMAX_API_BASE must be set BEFORE importing minimax_tts\")\n# safe to import now that the module-level check will pass\nimport skills.frontend_dev.scripts.minimax_tts as tts_mod","typeGuard":"def tts_env_ready() -> bool:\n    \"\"\"True only when MINIMAX_API_BASE is set (the import-time requirement).\"\"\"\n    return bool(os.getenv(\"MINIMAX_API_BASE\"))","tryCatchPattern":"try:\n    import minimax_tts  # triggers module-level API_BASE check\nexcept SystemExit as e:\n    if \"MINIMAX_API_BASE\" in str(e):\n        os.environ[\"MINIMAX_API_BASE\"] = \"https://api.minimax.io/v1\"\n        raise EnvironmentError(\"set MINIMAX_API_BASE then re-import\") from e\n    raise","preventionTips":["Set MINIMAX_API_BASE in the parent process BEFORE importing or running minimax_tts — the check is at import time.","Keep KEY and BASE together in one .env / CI secret block so neither is forgotten.","Add a preflight `test -n \"$MINIMAX_API_BASE\"` in scripts that launch the converter."],"tags":["config","environment","import-time","python","minimax","tts"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}