{"record":{"id":"3346a0885d281298","repo":"MiniMax-AI/skills","slug":"error-minimax-api-key-is-not-set-export-minima-3346a0","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_music.py","lineNumber":43,"sourceCode":"if not API_BASE:\n    raise SystemExit(\"ERROR: MINIMAX_API_BASE is not set.\")\n\n\ndef generate_music(\n    prompt: str = \"\",\n    lyrics: str = \"\",\n    model: str = \"music-2.5+\",\n    is_instrumental: bool = False,\n    lyrics_optimizer: bool = False,\n    sample_rate: int = 44100,\n    bitrate: int = 256000,\n    fmt: str = \"mp3\",\n    output_format: str = \"hex\",\n    timeout: int = 600,\n) -> dict:\n    \"\"\"Synchronous HTTP music generation. Returns dict with audio bytes and metadata.\"\"\"\n    if not API_KEY:\n        raise SystemExit(\"ERROR: MINIMAX_API_KEY is not set.\\n  export MINIMAX_API_KEY='your-key'\")\n\n    payload = {\n        \"model\": model,\n        \"audio_setting\": {\n            \"sample_rate\": sample_rate,\n            \"bitrate\": bitrate,\n            \"format\": fmt,\n        },\n        \"output_format\": output_format,\n    }\n\n    if prompt:\n        payload[\"prompt\"] = prompt\n    if lyrics:\n        payload[\"lyrics\"] = lyrics\n    if is_instrumental:\n        payload[\"is_instrumental\"] = True\n    if lyrics_optimizer:","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_music.py#L25-L61","documentation":"Raised by generate_music() when MINIMAX_API_KEY is absent or empty. The script reads the key once at import (API_KEY = os.getenv) and refuses to build the Authorization Bearer header without it, so it aborts before any network call to POST {API_BASE}/music_generation. Note API_BASE is validated at import time (line 26) and must already be set for execution to even reach this check.","triggerScenarios":"Calling generate_music() or running the CLI (`python minimax_music.py --prompt ... -o song.mp3`) in a shell, subprocess, or CI runner where MINIMAX_API_KEY is unset, empty string, or only defined in an un-sourced .env file.","commonSituations":"Key stored in .env but the file was never loaded (no python-dotenv, no `source .env`); fresh terminal/CI worker that did not inherit the export; typo in the variable name; key quoted incorrectly so the shell expanded to empty; running under a different user account that lacks the export in its profile.","solutions":["Export the key in the current shell: `export MINIMAX_API_KEY='your-key'`, then re-run the script.","If using a .env file, source it first (`set -a; source .env; set +a`) or load it in your wrapper, since this script does not auto-load dotenv.","For CI, inject the secret as an environment variable on the runner/step and confirm it is non-empty before the step that calls the script.","Verify quickly: `python -c \"import os;print(bool(os.getenv('MINIMAX_API_KEY')))\"` should print True in the exact environment that runs the script."],"exampleFix":"// before\n$ python minimax_music.py --prompt \"jazz\" -o out.mp3\nERROR: MINIMAX_API_KEY is not set.\n\n// after\n$ export MINIMAX_API_KEY='your-key'\n$ python minimax_music.py --prompt \"jazz\" -o out.mp3","handlingStrategy":"validation","validationCode":"import os\n\nkey = os.getenv(\"MINIMAX_API_KEY\")\nbase = os.getenv(\"MINIMAX_API_BASE\")\nif not key:\n    raise EnvironmentError(\"MINIMAX_API_KEY missing — export it before calling generate_music\")\nif not base:\n    raise EnvironmentError(\"MINIMAX_API_BASE missing — set the region host before importing minimax_music\")\n# only now import / call\nfrom skills.frontend_dev.scripts.minimax_music import generate_music","typeGuard":"def has_music_creds() -> bool:\n    \"\"\"True only when both env vars are non-empty.\"\"\"\n    return bool(os.getenv(\"MINIMAX_API_KEY\")) and bool(os.getenv(\"MINIMAX_API_BASE\"))","tryCatchPattern":"import subprocess, sys\ntry:\n    subprocess.run([sys.executable, \"minimax_music.py\", \"--prompt\", p, \"-o\", out], check=True)\nexcept subprocess.CalledProcessError as e:\n    if \"MINIMAX_API_KEY is not set\" in (e.stderr or \"\"):\n        raise EnvironmentError(\"set MINIMAX_API_KEY before running\") from e\n    raise","preventionTips":["Centralize credential loading in one bootstrap step that exports both MINIMAX_API_KEY and MINIMAX_API_BASE before any minimax script runs.","Assert creds in CI with `test -n \"$MINIMAX_API_KEY\"` so a missing secret fails the job early instead of at runtime.","Run `env | grep MINIMAX` as a preflight check in the exact shell/runner that launches the script."],"tags":["config","environment","authentication","python","minimax"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}