{"record":{"id":"f58e9d30792e06a7","repo":"MiniMax-AI/skills","slug":"api-error-code-msg","errorCode":null,"errorMessage":"API Error [{code}]: {msg}","messagePattern":"API Error \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"skills/frontend-dev/scripts/minimax_video.py","lineNumber":43,"sourceCode":"if not API_BASE:\n    raise SystemExit(\"ERROR: MINIMAX_API_BASE is not set.\")\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 create_task(\n    prompt: str,\n    model: str = \"MiniMax-Hailuo-2.3\",\n    duration: int = 6,\n    resolution: str = \"768P\",\n    prompt_optimizer: bool = True,\n) -> str:\n    \"\"\"Submit a video generation task. Returns task_id.\"\"\"\n    payload = {\n        \"model\": model,\n        \"prompt\": prompt,\n        \"duration\": duration,\n        \"resolution\": resolution,\n        \"prompt_optimizer\": prompt_optimizer,\n    }\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_video.py#L25-L61","documentation":"Shared _check_resp() helper: after HTTP 2xx on any video endpoint (POST video_generation, GET query/video_generation, GET files/retrieve), the body's base_resp.status_code is non-zero. This is MiniMax's application-level error channel; status_msg holds the detail and is surfaced for whichever endpoint produced it.","triggerScenarios":"Invalid model/resolution/duration combo on create (e.g. 1080P with a model that doesn't support it); prompt over 2000 chars or content-policy rejection; querying a task_id that doesn't belong to the account; retrieving a file_id that expired or is invalid; rate limit / quota on any of the three calls.","commonSituations":"Region/key mismatch (mainland key vs overseas host); model not enabled for the account; camera-command or bracket syntax the API rejects; querying a stale task; concurrent-request ceiling hit.","solutions":["Read the printed code + status_msg to identify which of the three endpoints failed and why.","For create failures, validate model in {MiniMax-Hailuo-2.3, MiniMax-Hailuo-02, T2V-01-Director, T2V-01}, duration in {6,10}, resolution in {720P,768P,1080P}, and prompt ≤2000 chars.","Match API_BASE region to the key region.","On transient/rate-limit codes, back off and retry; on auth codes (e.g. 1004) re-check the key."],"exampleFix":"// before: generic abort\nraise SystemExit(f\"API Error [{code}]: {msg}\")\n\n// after: classify retryable vs terminal\nclass MiniMaxApiError(RuntimeError):\n    def __init__(self, code, msg):\n        super().__init__(f\"{code}: {msg}\"); self.code = code\n    @property\n    def retryable(self):\n        return self.code in {1027, 1039}  # rate-limit style codes\nif code != 0:\n    raise MiniMaxApiError(code, msg)","handlingStrategy":"try-catch","validationCode":"def validate_video_params(model, duration, resolution, prompt):\n    assert model in {\"MiniMax-Hailuo-2.3\", \"MiniMax-Hailuo-02\", \"T2V-01-Director\", \"T2V-01\"}, f\"bad model {model}\"\n    assert duration in {6, 10}, f\"bad duration {duration}\"\n    assert resolution in {\"720P\", \"768P\", \"1080P\"}, f\"bad resolution {resolution}\"\n    assert len(prompt) <= 2000, \"prompt > 2000 chars\"","typeGuard":"def is_api_error(data: dict) -> bool:\n    base = data.get(\"base_resp\", {}) if isinstance(data, dict) else {}\n    return isinstance(base, dict) and base.get(\"status_code\", 0) != 0","tryCatchPattern":"import subprocess, sys\ntry:\n    subprocess.run([sys.executable, \"minimax_video.py\", prompt, \"-o\", out], check=True, capture_output=True, text=True)\nexcept subprocess.CalledProcessError as e:\n    msg = (e.stderr or \"\") + (e.stdout or \"\")\n    if \"API Error [\" in msg:\n        code, detail = parse_api_error(msg)\n        if code in TRANSIENT_CODES:\n            time.sleep(backoff); retry()\n        else:\n            raise RuntimeError(f\"video API {code}: {detail}\") from e\n    raise","preventionTips":["Pre-validate model/duration/resolution enums and prompt length before create_task.","Match API_BASE region to the key region.","Classify base_resp codes as retryable (rate limit) vs terminal.","Confirm the account tier has access to the requested model/resolution."],"tags":["api","network","validation","minimax","video"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}