{"record":{"id":"b36e08bea68a5216","repo":"MiniMax-AI/skills","slug":"error-minimax-api-key-is-not-set-export-minima-b36e08","errorCode":null,"errorMessage":"ERROR: MINIMAX_API_KEY is not set.\n  export MINIMAX_API_KEY='your-key'","messagePattern":"ERROR: MINIMAX_API_KEY is not set\\.\n  export MINIMAX_API_KEY='your-key'","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"critical","filePath":"skills/frontend-dev/scripts/minimax_tts.py","lineNumber":45,"sourceCode":"\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:\n        raise SystemExit(\"ERROR: MINIMAX_API_KEY is not set.\\n  export MINIMAX_API_KEY='your-key'\")\n\n    voice_setting = {\"voice_id\": voice_id, \"speed\": speed, \"vol\": volume, \"pitch\": pitch}\n    if emotion:\n        voice_setting[\"emotion\"] = emotion\n\n    payload = {\n        \"model\": model,\n        \"text\": text,\n        \"stream\": False,\n        \"voice_setting\": voice_setting,\n        \"audio_setting\": {\n            \"sample_rate\": sample_rate,\n            \"bitrate\": bitrate,\n            \"format\": fmt,\n            \"channel\": 1,\n        },\n        \"language_boost\": language_boost,\n        \"output_format\": \"hex\",","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_tts.py#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":".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.","solutions":["Export the key: `export MINIMAX_API_KEY='your-key'` then re-run.","Source your .env (`set -a; source .env; set +a`) since the script does not auto-load dotenv.","Confirm both vars together: `env | grep MINIMAX` should show non-empty KEY and BASE.","For CI, set MINIMAX_API_KEY as a secret env on the step and fail fast if empty."],"exampleFix":"// before\n$ python minimax_tts.py \"hello\" -o out.mp3\nERROR: MINIMAX_API_KEY is not set.\n\n// after\n$ export MINIMAX_API_KEY='your-key'\n$ python minimax_tts.py \"hello\" -o out.mp3","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"MINIMAX_API_KEY\"):\n    raise EnvironmentError(\"MINIMAX_API_KEY must be set before calling tts()\")\nif not os.getenv(\"MINIMAX_API_BASE\"):\n    raise EnvironmentError(\"MINIMAX_API_BASE must be set before importing minimax_tts\")\nfrom skills.frontend_dev.scripts.minimax_tts import tts","typeGuard":"def has_tts_key() -> bool:\n    \"\"\"True only when the TTS key env var is non-empty.\"\"\"\n    return bool(os.getenv(\"MINIMAX_API_KEY\"))","tryCatchPattern":"import subprocess, sys\ntry:\n    subprocess.run([sys.executable, \"minimax_tts.py\", text, \"-o\", out], check=True, capture_output=True, text=True)\nexcept subprocess.CalledProcessError as e:\n    if \"MINIMAX_API_KEY is not set\" in (e.stderr or \"\"):\n        raise EnvironmentError(\"export MINIMAX_API_KEY first\") from e\n    raise","preventionTips":["Assert both MINIMAX env vars in one bootstrap step before any TTS call.","In CI, gate the step on `test -n \"$MINIMAX_API_KEY\"`.","Run `env | grep MINIMAX` as a preflight in the exact launching shell."],"tags":["config","environment","authentication","python","minimax","tts"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}