{"record":{"id":"eb9b10d4a2db6075","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-returned-an-invalid-subscription-respon","errorCode":null,"errorMessage":"ElevenLabs returned an invalid subscription response","messagePattern":"ElevenLabs returned an invalid subscription response","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":136,"sourceCode":"            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        )\n    tier = str(payload.get(\"tier\") or \"\").strip().lower()\n    if not tier:\n        raise ElevenLabsMusicError(\n            \"ElevenLabs subscription response does not include an account tier\"\n        )\n    if tier == \"free\":\n        raise ElevenLabsPaidPlanRequiredError(\n            \"ElevenLabs Music API requires a paid plan; \"","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L118-L154","documentation":"ElevenLabsMusicError raised inside test_connection() when response.json() raises ValueError — the 2xx subscription response body was not valid JSON (truncated body, HTML error page from a proxy, or a decode error). The original ValueError is chained via 'from exc' for debugging. The request uses stream=True, so a truncated read is plausible on flaky connections.","triggerScenarios":"The subscription endpoint returns 200 with HTML (captive portal / proxy error page), a truncated JSON body due to a dropped connection, or a custom music_base_url returning a non-JSON success page.","commonSituations":"Corporate proxies intercepting HTTPS; misconfigured base URLs; captive portals on hotel networks; flaky mobile connections where the body cuts off mid-stream.","solutions":["Retry once — truncated responses on unstable connections are the most common cause.","If it persists, inspect what the configured music_base_url actually returns (curl the /user/subscription URL) and fix or unset the proxy/base URL override.","Check whether an intercepting proxy or captive portal is in play (does the body look like HTML?)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    test_connection()\nexcept ElevenLabsMusicError as e:\n    if 'invalid subscription response' in str(e):\n        time.sleep(2)\n        return test_connection()  # truncated body — retry once\n    raise","preventionTips":["Retry once on parse failures — truncated streamed bodies are usually transient.","Keep the default music_base_url unless a proxy is proven transparent.","Log the response Content-Type when debugging; HTML from a proxy is the usual culprit."],"tags":["elevenlabs","json","response-parsing","proxy"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}