{"record":{"id":"858d16d750280fee","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-account-check-failed-response-status","errorCode":null,"errorMessage":"ElevenLabs account check failed ({response.status_code}): {_safe_response_error(response)}","messagePattern":"ElevenLabs account check failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":128,"sourceCode":"    响应中的账单和用量详情不会写入日志，避免记录账号隐私。\n    \"\"\"\n    api_key = get_api_key()\n    if not api_key:\n        raise ElevenLabsAuthenticationError(\"ElevenLabs API key is required\")\n    try:\n        with requests.get(\n            f\"{_base_url()}{SUBSCRIPTION_PATH}\",\n            headers={\"xi-api-key\": api_key},\n            timeout=(15, 30),\n            stream=True,\n        ) as response:\n            if response.status_code == 401:\n                raise ElevenLabsAuthenticationError(\n                    \"ElevenLabs API key was rejected (401): \"\n                    f\"{_safe_response_error(response)}\"\n                )\n            if not response.ok:\n                raise ElevenLabsMusicError(\n                    \"ElevenLabs account check failed \"\n                    f\"({response.status_code}): \"\n                    f\"{_safe_response_error(response)}\"\n                )\n            try:\n                payload = response.json()\n            except ValueError as exc:\n                raise ElevenLabsMusicError(\n                    \"ElevenLabs returned an invalid subscription response\"\n                ) from exc\n    except requests.RequestException as exc:\n        raise ElevenLabsMusicError(\n            f\"failed to connect to ElevenLabs: {exc}\"\n        ) from exc\n    if not isinstance(payload, dict):\n        raise ElevenLabsMusicError(\n            \"ElevenLabs returned an unexpected subscription response\"\n        )","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L110-L146","documentation":"ElevenLabsMusicError raised by test_connection() when the subscription endpoint answers with a non-ok status other than 401 (402/403/429/5xx...). The message includes the status code and _safe_response_error(response), which streams at most 500 bytes of the body — enough to see ElevenLabs' reason without polluting logs or reading unbounded error content. 401 is handled separately as an authentication error.","triggerScenarios":"Any 2xx-以外的 status that is not 401: 403 when the key lacks permission for the subscription endpoint, 429 rate limiting, 5xx outages, or a misconfigured music_base_url pointing at a gateway that returns 404/502.","commonSituations":"Rate-limited keys during batch video generation; per-endpoint restricted keys; corporate proxies or custom music_base_url values returning non-ElevenLabs errors; transient API incidents.","solutions":["Read the embedded status/body detail: 429 means wait/back off; 403 means the key lacks subscription-read permission; 5xx means retry later.","If using a custom music_base_url, verify the gateway actually proxies /v1/user/subscription.","Retry after a short backoff for transient 5xx; surface the status to the user instead of retrying 403."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        return test_connection()\n    except ElevenLabsMusicError as e:\n        if 'account check failed (429' in str(e) or ' 5' in str(e):\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Rate-limit connection tests (once per session, not per request).","Read the embedded status code: 403 is permanent (fix key permissions), 429/5xx are transient (back off).","If using a custom music_base_url, ensure it proxies the subscription path faithfully."],"tags":["elevenlabs","http-error","api","rate-limit"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}