{"record":{"id":"aec0cac8c3c6c901","repo":"MiniMax-AI/skills","slug":"error-minimax-api-key-is-not-set-export-minima","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_image.py","lineNumber":32,"sourceCode":"import 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\nASPECT_RATIOS = [\"1:1\", \"16:9\", \"4:3\", \"3:2\", \"2:3\", \"3:4\", \"9:16\", \"21:9\"]\n\n\ndef _headers():\n    if not API_KEY:\n        raise SystemExit(\"ERROR: MINIMAX_API_KEY is not set.\\n  export MINIMAX_API_KEY='your-key'\")\n    return {\n        \"Authorization\": f\"Bearer {API_KEY}\",\n        \"Content-Type\": \"application/json\",\n    }\n\n\ndef generate_image(\n    prompt: str,\n    model: str = \"image-01\",\n    aspect_ratio: str = \"1:1\",\n    n: int = 1,\n    response_format: str = \"url\",\n    prompt_optimizer: bool = False,\n    seed: int = None,\n) -> dict:\n    \"\"\"Generate image(s). Returns API response dict.\"\"\"\n    payload = {\n        \"model\": model,","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_image.py#L14-L50","documentation":"`raise SystemExit(\"ERROR: MINIMAX_API_KEY is not set...\\n  export MINIMAX_API_KEY='your-key'\")` inside `_headers()` of `minimax_image.py`. Unlike the base-URL check (which runs at import), the API key check is deferred until `_headers()` is first called — i.e. when a request is actually made. This lets the module import without a key but blocks any real call. The message includes the exact export command.","triggerScenarios":"Calling `generate_image(...)` (which calls `_headers()`) when `MINIMAX_API_KEY` is unset or empty. The base URL may already be set; the key specifically is missing.","commonSituations":"Base URL is configured but the key was never exported, the key variable was misspelled, or a new shell/session lost the export. Also when the key is set to an empty string.","solutions":["Export the key: `export MINIMAX_API_KEY='your-key'` (use a real key from the MiniMax console), then rerun.","Persist it in your shell profile or a sourced `.env` so new sessions keep it.","Verify with `printenv MINIMAX_API_KEY` that the value is present and non-empty."],"exampleFix":"# before\nexport MINIMAX_API_BASE='https://api.minimax.io/v1'  # base set, key missing\npython minimax_image.py \"cat\" -o cat.png  # SystemExit on key\n\n# after\nexport MINIMAX_API_KEY='your-real-key'\npython minimax_image.py \"cat\" -o cat.png","handlingStrategy":"validation","validationCode":"import os, sys\n\nAPI_KEY = os.getenv(\"MINIMAX_API_KEY\")\nif not API_KEY or len(API_KEY) < 16:\n    print(\"ERROR: MINIMAX_API_KEY missing or too short. export MINIMAX_API_KEY='your-key'\", file=sys.stderr)\n    sys.exit(2)","typeGuard":"def _has_key() -> bool:\n    k = os.getenv(\"MINIMAX_API_KEY\")\n    return isinstance(k, str) and len(k) >= 16","tryCatchPattern":null,"preventionTips":["Store secrets in a password manager or secret backend, not loose in shell history.","Add the key to a sourced `.env` (chmod 600) so new sessions keep it.","Validate the key length/format before the first request for a clearer message.","Keep base URL and key region-aligned (overseas key + overseas base URL)."],"tags":["python","config","env","api","minimax","auth","cli"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}