{"record":{"id":"5d72569aa30f1f5a","repo":"MiniMax-AI/skills","slug":"error-minimax-api-key-is-not-set-n-export-minim","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/gif-sticker-maker/scripts/minimax_image.py","lineNumber":33,"sourceCode":"import 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\")\n    with open(image_path, \"rb\") as f:\n        raw = f.read()\n    return f\"data:image/{mime};base64,{base64.b64encode(raw).decode()}\"\n\n\ndef generate_image(\n    prompt: str,","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/gif-sticker-maker/scripts/minimax_image.py#L15-L51","documentation":"Raised inside the _headers() helper, called lazily when generate_image() makes its POST. API_KEY is falsy so the Authorization Bearer header cannot be built. Because the check is in _headers (not at import), importing the module succeeds; it only fails when a request is attempted.","triggerScenarios":"Calling generate_image() or running the CLI with MINIMAX_API_KEY unset/empty (while API_BASE was set so import succeeded).","commonSituations":".env not sourced; CI secret empty/masked; different shell/subprocess than where the export ran; key var name typo; key set interactively but not in the runner subprocess.","solutions":["Export the key: `export MINIMAX_API_KEY='your-key'` then re-run.","Source .env before launching; confirm with `env | grep MINIMAX`.","In CI, inject MINIMAX_API_KEY as a secret env on the step and assert non-empty up front."],"exampleFix":"// before\n$ python minimax_image.py \"a cat\" -o cat.png\nERROR: MINIMAX_API_KEY is not set.\n\n// after\n$ export MINIMAX_API_KEY='your-key'\n$ python minimax_image.py \"a cat\" -o cat.png","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"MINIMAX_API_KEY\"):\n    raise EnvironmentError(\"MINIMAX_API_KEY must be set before calling generate_image()\")\nif not os.getenv(\"MINIMAX_API_BASE\"):\n    raise EnvironmentError(\"MINIMAX_API_BASE must be set before importing minimax_image\")\nfrom skills.gif_sticker_maker.scripts.minimax_image import generate_image","typeGuard":"def has_image_key() -> bool:\n    \"\"\"True only when the image API 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_image.py\", prompt, \"-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 image call.","Gate CI steps on `test -n \"$MINIMAX_API_KEY\"`.","Run `env | grep MINIMAX` as a preflight in the launching shell."],"tags":["config","environment","authentication","python","minimax","image"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}