{"record":{"id":"ff243141658cc2da","repo":"MiniMax-AI/skills","slug":"api-error-base-resp-get-status-code-base-ff2431","errorCode":null,"errorMessage":"API Error [{base_resp.get('status_code')}]: {base_resp.get('status_msg')}","messagePattern":"API Error \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"skills/gif-sticker-maker/scripts/minimax_image.py","lineNumber":85,"sourceCode":"        \"prompt_optimizer\": prompt_optimizer,\n    }\n    if seed is not None:\n        payload[\"seed\"] = seed\n    if subject_reference:\n        payload[\"subject_reference\"] = subject_reference\n\n    resp = requests.post(\n        f\"{API_BASE}/image_generation\",\n        headers=_headers(),\n        json=payload,\n        timeout=120,\n    )\n    resp.raise_for_status()\n    data = resp.json()\n\n    base_resp = data.get(\"base_resp\", {})\n    if base_resp.get(\"status_code\", 0) != 0:\n        raise SystemExit(f\"API Error [{base_resp.get('status_code')}]: {base_resp.get('status_msg')}\")\n\n    return data\n\n\ndef download_and_save(url: str, output_path: str):\n    \"\"\"Download image from URL and save.\"\"\"\n    resp = requests.get(url, timeout=60)\n    resp.raise_for_status()\n    with open(output_path, \"wb\") as f:\n        f.write(resp.content)\n    return len(resp.content)\n\n\ndef main():\n    p = argparse.ArgumentParser(description=\"MiniMax Text-to-Image\")\n    p.add_argument(\"prompt\", help=\"Image description (max 1500 chars)\")\n    p.add_argument(\"-o\", \"--output\", required=True, help=\"Output file path (.png/.jpg)\")\n    p.add_argument(\"--model\", default=\"image-01\", help=\"Model (default: image-01)\")","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/gif-sticker-maker/scripts/minimax_image.py#L67-L103","documentation":"Raised as SystemExit after POST {API_BASE}/image_generation returns HTTP 200 but the body's base_resp.status_code is non-zero. MiniMax signals application-level failures (content moderation, invalid parameters, quota) through this nested field instead of an HTTP error, so resp.raise_for_status() does not catch them. The script surfaces the API's own status_code and status_msg so the CLI halts immediately.","triggerScenarios":"POST /image_generation returns JSON where base_resp.status_code != 0. Typical: prompt violates content policy, aspect_ratio is not in [1:1,16:9,4:3,3:2,2:3,3:4,9:16,21:9], prompt exceeds 1500 chars, model name is invalid/default-mismatched, or the account has no image-generation quota left.","commonSituations":"Account out of credits; prompt contains policy-flagged terms; passing a model name copied from docs that differs from the default 'image-01'; custom aspect_ratio string the API rejects; concurrent requests tripping a soft rate limit.","solutions":["Read status_msg verbatim — it is the API's own reason for the rejection.","Shorten/sanitize the prompt to stay under 1500 chars and avoid flagged terms.","Confirm aspect_ratio is in ASPECT_RATIOS and model is valid (default image-01).","Check the MiniMax console for remaining image-generation quota and billing.","If rate-limited, add backoff between successive generate_image() calls."],"exampleFix":"# before\nresult = generate_image(prompt=p, aspect_ratio='21:9')  # raises SystemExit on API soft-error\n\n# after\ntry:\n    result = generate_image(prompt=p, aspect_ratio='21:9')\nexcept SystemExit as e:\n    print(f'image generation failed: {e}', file=sys.stderr)\n    sys.exit(1)","handlingStrategy":"try-catch","validationCode":"VALID_RATIOS = {'1:1','16:9','4:3','3:2','2:3','3:4','9:16','21:9'}\nif aspect_ratio not in VALID_RATIOS:\n    raise ValueError(f'aspect_ratio must be one of {sorted(VALID_RATIOS)}')\nif not prompt or len(prompt) > 1500:\n    raise ValueError('prompt must be 1-1500 chars')","typeGuard":null,"tryCatchPattern":"try:\n    result = generate_image(prompt=p, aspect_ratio=r)\nexcept SystemExit as e:\n    # MiniMax scripts abort via SystemExit on API soft-errors\n    raise RuntimeError(f'image generation failed: {e}') from e","preventionTips":["Validate prompt length (<1500) and aspect_ratio against ASPECT_RATIOS before calling.","Treat base_resp.status_code as the real success signal, not HTTP 200.","Sanitize prompts for policy terms before submission."],"tags":["api","minimax","image-generation","content-policy"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}