{"record":{"id":"8c2a34107ead2414","repo":"MiniMax-AI/skills","slug":"api-error-base-resp-get-status-code-base-8c2a34","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/frontend-dev/scripts/minimax_tts.py","lineNumber":81,"sourceCode":"        \"output_format\": \"hex\",\n    }\n\n    resp = requests.post(\n        f\"{API_BASE}/t2a_v2\",\n        headers={\n            \"Authorization\": f\"Bearer {API_KEY}\",\n            \"Content-Type\": \"application/json\",\n        },\n        json=payload,\n        timeout=timeout,\n    )\n    resp.raise_for_status()\n    data = resp.json()\n\n    # Check API-level error\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    audio_hex = data.get(\"data\", {}).get(\"audio\", \"\")\n    if not audio_hex:\n        raise SystemExit(f\"No audio in response: {json.dumps(data, indent=2)}\")\n\n    return bytes.fromhex(audio_hex)\n\n\ndef main():\n    p = argparse.ArgumentParser(description=\"MiniMax Sync TTS (HTTP)\")\n    p.add_argument(\"text\", help=\"Text to synthesize (max 10000 chars)\")\n    p.add_argument(\"-o\", \"--output\", required=True, help=\"Output file path\")\n    p.add_argument(\"-v\", \"--voice\", default=\"male-qn-qingse\", help=\"Voice ID\")\n    p.add_argument(\"--model\", default=\"speech-2.8-hd\", help=\"Model (default: speech-2.8-hd)\")\n    p.add_argument(\"--speed\", type=float, default=1.0, help=\"Speed 0.5-2.0\")\n    p.add_argument(\"--volume\", type=float, default=1.0, help=\"Volume 0.1-10\")\n    p.add_argument(\"--pitch\", type=int, default=0, help=\"Pitch -12 to 12\")\n    p.add_argument(\"--emotion\", default=\"\", help=\"Emotion tag (happy/sad/angry/...)\")","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/frontend-dev/scripts/minimax_tts.py#L63-L99","documentation":"The POST to {API_BASE}/t2a_v2 returned HTTP 2xx (raise_for_status passed) but the body's base_resp.status_code is non-zero — an application-level TTS error. status_msg carries the detail. This is the same base_resp contract as the other MiniMax endpoints.","triggerScenarios":"Invalid voice_id; text longer than 10000 chars; speed outside 0.5–2.0; volume outside 0.1–10; pitch outside -12..12; an unsupported emotion value; an invalid sample_rate/bitrate/format combination for the chosen model; unsupported language_boost; content-policy rejection of the text; rate limit or quota.","commonSituations":"Passing a voice_id from a different model tier than speech-2.8-hd; requesting wav/flac with a sample_rate the model doesn't support; emotion tag spelled wrong; long text exceeding the 10000-char ceiling; region/key mismatch (overseas key vs mainland host).","solutions":["Read status_code/status_msg — they pin the cause (e.g. invalid param, length, content, rate limit).","Clamp/validate inputs before sending: text ≤10000 chars, speed 0.5–2.0, volume 0.1–10, pitch -12..12.","Confirm the voice_id and model are a valid pairing for your account/region.","Match the API_BASE region to the key region and retry on transient rate-limit codes after backoff."],"exampleFix":"// before: send unchecked user text straight to the API\ntts(text=user_text, voice_id=vid)\n\n// after: validate bounds to avoid a base_resp rejection\nif len(user_text) > 10000:\n    raise ValueError(\"text exceeds 10000 chars\")\nif not (0.5 <= speed <= 2.0) or not (0.1 <= volume <= 10):\n    raise ValueError(\"speed/volume out of range\")\ntts(text=user_text[:10000], voice_id=vid, speed=speed, volume=volume)","handlingStrategy":"try-catch","validationCode":"def validate_tts(text, voice_id, speed, volume, pitch, model=\"speech-2.8-hd\"):\n    assert len(text) <= 10000, \"text > 10000 chars\"\n    assert 0.5 <= speed <= 2.0, \"speed out of 0.5-2.0\"\n    assert 0.1 <= volume <= 10, \"volume out of 0.1-10\"\n    assert -12 <= pitch <= 12, \"pitch out of -12..12\"\n    assert voice_id, \"voice_id required\"\n    assert model, \"model required\"","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_tts.py\", text, \"-o\", out, \"-v\", vid], 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\"tts API {code}: {detail}\") from e\n    raise","preventionTips":["Clamp text length, speed, volume, pitch to documented ranges before calling tts().","Verify the voice_id is valid for the chosen model tier and region.","Match API_BASE region to the key region to avoid base_resp auth/policy errors.","Classify base_resp codes as retryable vs terminal instead of blanket-aborting."],"tags":["api","network","validation","minimax","tts"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}