{"record":{"id":"2c5c7f1baa6e9c6a","repo":"harry0703/MoneyPrinterTurbo","slug":"elevenlabs-returned-an-unexpected-subscription-res","errorCode":null,"errorMessage":"ElevenLabs returned an unexpected subscription response","messagePattern":"ElevenLabs returned an unexpected subscription response","errorType":"exception","errorClass":"ElevenLabsMusicError","httpStatus":null,"severity":"error","filePath":"app/services/elevenlabs_music.py","lineNumber":144,"sourceCode":"                )\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; \"\n            \"the current account is on the free tier\"\n        )\n    logger.info(f\"ElevenLabs account and plan check succeeded: tier={tier}\")\n    return payload\n\n\ndef validate_generation_access() -> None:\n    \"\"\"","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/elevenlabs_music.py#L126-L162","documentation":"ElevenLabsMusicError raised by test_connection() when the parsed subscription payload is JSON but not a dict — e.g. a bare string, list, or number. The ElevenLabs API returns a JSON object, so this indicates a non-ElevenLabs responder: a custom music_base_url, a mock server, or an intermediary returning scalar/array JSON. It is distinct from error 29 (body not JSON at all) and fires only after json() succeeded.","triggerScenarios":"config.elevenlabs.music_base_url points at a stub/mock returning '[]' or '\"ok\"' with status 200; a service-mesh sidecar answering the path with a JSON array; an API version change that altered the payload shape.","commonSituations":"Testing against a local mock server; custom enterprise gateways rewriting responses; upstream API contract changes after an ElevenLabs update.","solutions":["Point music_base_url at the real API (or unset it to use the default) when doing real account checks.","If using a mock, make it return a JSON object shaped like the subscription response ({\"tier\": \"creator\", ...}).","If neither applies, dump the raw body once (curl) and compare against the documented subscription schema."],"exampleFix":"# mock server fix\n# before: b'[]'\n# after\nb'{\"tier\": \"creator\"}'","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    test_connection()\nexcept ElevenLabsMusicError as e:\n    if 'unexpected subscription response' in str(e):\n        log('music_base_url may point at a non-ElevenLabs responder')\n        raise ConfigError('verify music_base_url configuration') from e","preventionTips":["Leave music_base_url unset unless a compatible gateway is verified end-to-end.","Make mock servers return JSON objects matching the subscription schema.","Re-check custom gateways after any API version bump."],"tags":["elevenlabs","response-schema","json","mock"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}