{"record":{"id":"c70aee10d3111163","repo":"MiniMax-AI/skills","slug":"error-minimax-api-base-is-not-set-c70aee","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/gif-sticker-maker/scripts/minimax_image.py","lineNumber":26,"sourceCode":"  python3 minimax_image.py \"Mountain landscape\" -o bg.png --ratio 16:9\n  python3 minimax_image.py \"Funko Pop figurine waving\" -o sticker.png --subject-ref photo.jpg\n\nEnv: MINIMAX_API_KEY (required)\n\"\"\"\n\nimport os\nimport sys\nimport json\nimport base64\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 _encode_image(image_path: str) -> str:\n    \"\"\"Read local image file and return base64 data URI.\"\"\"\n    ext = os.path.splitext(image_path)[1].lower().lstrip(\".\")\n    mime_map = {\"jpg\": \"jpeg\", \"jpeg\": \"jpeg\", \"png\": \"png\", \"webp\": \"webp\"}\n    mime = mime_map.get(ext, \"jpeg\")","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/gif-sticker-maker/scripts/minimax_image.py#L8-L44","documentation":"Fires at MODULE IMPORT TIME (top-level line 26). API_BASE is falsy, so importing minimax_image or running the CLI aborts before any function runs. The base URL selects the China-mainland vs overseas host used for POST {API_BASE}/image_generation.","triggerScenarios":"Importing the module or running the CLI with MINIMAX_API_BASE unset/empty. Because it is module-level, `import minimax_image` alone triggers it; setting the var after import is too late.","commonSituations":"Only the API key exported; .env missing the base URL; CI has the key but not the host; importing the module from another script before sourcing env.","solutions":["Export the region host: `export MINIMAX_API_BASE='https://api.minimax.io/v1'` (overseas) or `https://api.minimaxi.com/v1` (China mainland).","Set it in the same process before import/run; add it to .env and CI secrets next to the key.","Verify: `python -c \"import os;print(os.getenv('MINIMAX_API_BASE'))\"` in the launch environment."],"exampleFix":"// before\n$ python minimax_image.py \"a cat\" -o cat.png\nERROR: MINIMAX_API_BASE is not set.\n\n// after\n$ export MINIMAX_API_BASE='https://api.minimax.io/v1'\n$ python minimax_image.py \"a cat\" -o cat.png","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_image\")\nimport skills.gif_sticker_maker.scripts.minimax_image as image_mod","typeGuard":"def image_env_ready() -> bool:\n    \"\"\"True only when the import-time API_BASE requirement is satisfied.\"\"\"\n    return bool(os.getenv(\"MINIMAX_API_BASE\"))","tryCatchPattern":"try:\n    import minimax_image  # module-level API_BASE check\nexcept SystemExit as e:\n    if \"MINIMAX_API_BASE\" in str(e):\n        raise EnvironmentError(\"set MINIMAX_API_BASE before importing minimax_image\") from e\n    raise","preventionTips":["Set MINIMAX_API_BASE in the parent process BEFORE importing or running minimax_image.","Keep KEY and BASE together in .env / CI secrets.","Preflight `test -n \"$MINIMAX_API_BASE\"` in launch scripts."],"tags":["config","environment","import-time","python","minimax","image"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}