{"record":{"id":"3327d537e58cea17","repo":"MiniMax-AI/skills","slug":"api-error-code-msg-3327d5","errorCode":null,"errorMessage":"API Error [{code}]: {msg}","messagePattern":"API Error \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"skills/gif-sticker-maker/scripts/minimax_video.py","lineNumber":63,"sourceCode":"    \"T2V-01\",\n]\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 _check_resp(data):\n    base_resp = data.get(\"base_resp\", {})\n    code = base_resp.get(\"status_code\", 0)\n    if code != 0:\n        msg = base_resp.get(\"status_msg\", \"Unknown error\")\n        raise SystemExit(f\"API Error [{code}]: {msg}\")\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, \"png\")\n\n    with open(image_path, \"rb\") as f:\n        raw = f.read()\n\n    return f\"data:image/{mime};base64,{base64.b64encode(raw).decode()}\"\n\n\ndef create_task(\n    prompt: str,\n    model: str = \"MiniMax-Hailuo-2.3\",\n    duration: int = 6,","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/gif-sticker-maker/scripts/minimax_video.py#L45-L81","documentation":"Central response validator for the video API (_check_resp). After every successful HTTP call, it inspects base_resp.status_code; any non-zero value aborts via SystemExit with the API's code and message. Common codes: 1004 invalid/expired token, 1027 content moderation, 1xxx config/payload errors.","triggerScenarios":"POST video_generation, GET query/video_generation, or GET files/retrieve returns base_resp.status_code != 0. E.g. invalid model name, expired token (1004), unsupported duration/resolution for the model, or content moderation on the prompt/image.","commonSituations":"Token expired mid-session; model not enabled for the account; duration/resolution pair unsupported by the chosen model; prompt or I2V first-frame tripped moderation; account suspended.","solutions":["Match the numeric code: 1004 -> re-authenticate/refresh key; 1027 -> content policy; 1xxx -> fix the payload.","Verify the model is in T2V_MODELS or I2V_MODELS for the chosen mode.","Check duration (6/10) and resolution (720P/768P/1080P) are valid for the model.","Re-set MINIMAX_API_KEY if the code indicates an auth failure."],"exampleFix":"# before\ntask_id = create_task(prompt=p, model='MiniMax-Hailuo-2.3')  # SystemExit: API Error [1004]: ...\n\n# after\ntry:\n    task_id = create_task(prompt=p, model='MiniMax-Hailuo-2.3')\nexcept SystemExit as e:\n    raise RuntimeError(f'video API rejected request: {e}') from e","handlingStrategy":"try-catch","validationCode":"assert model in set(T2V_MODELS + I2V_MODELS), f'unknown model: {model}'\nassert duration in (6, 10), 'duration must be 6 or 10'\nassert resolution in ('720P','768P','1080P'), 'bad resolution'","typeGuard":null,"tryCatchPattern":"try:\n    task_id = create_task(...)\nexcept SystemExit as e:\n    msg = str(e)\n    if 'API Error [1004]' in msg:\n        os.environ['MINIMAX_API_KEY'] = refresh_key()\n    else:\n        raise RuntimeError(msg) from e","preventionTips":["Treat base_resp.status_code (not HTTP status) as the real success signal.","Whitelist model/duration/resolution values before calling create_task().","Refresh tokens proactively for long-running sessions."],"tags":["api","minimax","video-generation","authentication"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}