{"record":{"id":"3d0684acad768a74","repo":"MiniMax-AI/skills","slug":"error-minimax-api-base-is-not-set","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_image.py","lineNumber":25,"sourceCode":"  python minimax_image.py \"A cat in space\" -o cat.png\n  python minimax_image.py \"Mountain landscape\" -o bg.png --ratio 16:9\n  python minimax_image.py \"Product icons\" -o icons.png -n 4 --ratio 1:1\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\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,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_image.py#L7-L43","documentation":"`raise SystemExit(\"ERROR: MINIMAX_API_BASE is not set.\")` at module load of `minimax_image.py`. `MINIMAX_API_BASE` (the API origin, e.g. `https://api.minimax.io/v1` for overseas or `https://api.minimaxi.com/v1` for China mainland) is read at import time; if unset the script aborts immediately because every request URL is built from it. `SystemExit` exits with a non-zero code rather than raising a traceback.","triggerScenarios":"Importing or running the script in a shell where `MINIMAX_API_BASE` was never exported. The check runs at top-level module code, so even `import minimax_image` triggers it.","commonSituations":"New machine/container without the env set, forgetting to source the env file, or a typo in the variable name. Note the key is `MINIMAX_API_BASE` (the base URL), distinct from `MINIMAX_API_KEY`.","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).","Add it to your shell profile (`~/.bashrc`/`.zshrc`) or a `.env` file you source before running.","Confirm with `printenv MINIMAX_API_BASE` that it is set in the active shell (child processes inherit only exported vars)."],"exampleFix":"# before — env not set\npython minimax_image.py \"cat\" -o cat.png  # SystemExit\n\n# after\nexport MINIMAX_API_BASE='https://api.minimax.io/v1'\nexport MINIMAX_API_KEY='your-key'\npython minimax_image.py \"cat\" -o cat.png","handlingStrategy":"validation","validationCode":"import os, sys\n\nAPI_BASE = os.getenv(\"MINIMAX_API_BASE\")\nif not API_BASE:\n    print(\"ERROR: set MINIMAX_API_BASE (overseas: https://api.minimax.io/v1, CN: https://api.minimaxi.com/v1)\", file=sys.stderr)\n    sys.exit(2)","typeGuard":"def _valid_base(url: str | None) -> bool:\n    return bool(url) and url.startswith(\"http\") and url.rstrip(\"/\").endswith(\"/v1\")","tryCatchPattern":null,"preventionTips":["Document required env vars in a `.env.example` and README.","Validate `MINIMAX_API_BASE` shape (must end in `/v1`) and set a default per region if appropriate.","Source a single `.env` file in every shell/session that runs the script.","Use a settings loader (pydantic-settings) so missing vars produce one consolidated error."],"tags":["python","config","env","api","minimax","cli"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}