{"record":{"id":"95532ce9c03b74a1","repo":"BerriAI/litellm","slug":"failed-to-parse-minimax-response-e","errorCode":null,"errorMessage":"Failed to parse MiniMax response: {e}","messagePattern":"Failed to parse MiniMax response: (.+?)","errorType":"exception","errorClass":"MinimaxException","httpStatus":500,"severity":"error","filePath":"litellm/llms/minimax/text_to_speech/transformation.py","lineNumber":379,"sourceCode":"            # We need to create a response that contains the decoded audio bytes\n            # Remove gzip encoding headers to avoid decompression issues\n            clean_headers: Final = dict(raw_response.headers)\n            clean_headers.pop(\"content-encoding\", None)\n            clean_headers.pop(\"transfer-encoding\", None)\n            clean_headers[\"content-length\"] = str(len(audio_bytes))\n\n            # Create a new response object with the binary content\n            binary_response: Final = httpx.Response(\n                status_code=200,\n                headers=clean_headers,\n                content=audio_bytes,\n                request=raw_response.request,\n            )\n\n            return HttpxBinaryResponseContent(binary_response)\n\n        except json.JSONDecodeError as e:\n            raise MinimaxException(\n                status_code=500,\n                message=f\"Failed to parse MiniMax response: {e}\",\n                headers=dict(raw_response.headers),\n            )\n        except Exception as e:\n            if isinstance(e, MinimaxException):\n                raise\n            raise MinimaxException(\n                status_code=500,\n                message=f\"Error processing MiniMax response: {e}\",\n                headers=dict(raw_response.headers),\n            )\n\n    def get_complete_url(\n        self,\n        model: str,\n        api_base: str | None,\n        litellm_params: dict,","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/minimax/text_to_speech/transformation.py#L361-L397","documentation":"Raised by litellm's MiniMax text-to-speech transformer when the MiniMax TTS API returns a body that is not valid JSON (a json.JSONDecodeError occurs while parsing). This usually means the upstream returned an HTML/plain-text error page or an unexpected success payload instead of the expected JSON. The error is wrapped in a MinimaxException with HTTP 500 and the upstream response headers attached.","triggerScenarios":"Calling litellm.text_to_speech() / speech() with model='minimax/tts-...' where the MiniMax endpoint returns a non-JSON body: invalid or expired MiniMax API key (auth error page), wrong api_base (proxy/gateway returning HTML), rate-limit or quota page, or a truncated response from a network interruption.","commonSituations":"Setting MINIMAX_API_KEY incorrectly, pointing api_base at a URL that returns an HTML 404/502, calling from a region MiniMax blocks (Cloudflare interstitial), or a model name the TTS endpoint rejects causing a plain-text error.","solutions":["Verify MINIMAX_API_KEY (or the api_key param) is set and valid for the MiniMax TTS platform.","Check api_base — it must be the real MiniMax TTS endpoint, not a web page or generic MiniMax chat host.","Log raw_response.text (via litellm verbose logs or a proxy hook) to see the actual non-JSON body returned upstream.","Confirm the model name is a MiniMax TTS model (e.g. speech-01-hd/turbo) supported by the endpoint.","Retry once after fixing config; if upstream is flaky, wrap the call in a retry with backoff."],"exampleFix":"# before\nresp = litellm.text_to_speech(model=\"minimax/tts-01\", input=\"hi\")\n\n# after — explicit key + base and a readable failure\nimport litellm\nresp = litellm.text_to_speech(\n    model=\"minimax/tts-02-hd-preview\",\n    input=\"hello world\",\n    api_key=os.environ[\"MINIMAX_API_KEY\"],          # fail fast if unset\n    api_base=\"https://api.minimax.chat/v1/t2a_v2\",  # exact TTS endpoint\n)","handlingStrategy":"try-catch","validationCode":"import os\nassert os.getenv(\"MINIMAX_API_KEY\"), \"MINIMAX_API_KEY must be set before calling MiniMax TTS\"","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import APIError\ntry:\n    audio = litellm.text_to_speech(model=\"minimax/tts-02-hd-preview\", input=text)\nexcept APIError as e:\n    if \"Failed to parse MiniMax response\" in str(e):\n        # non-JSON upstream body: inspect key/base, do not blind-retry\n        raise RuntimeError(f\"MiniMax returned non-JSON body (check api_key/api_base): {e}\") from e\n    raise","preventionTips":["Set MINIMAX_API_KEY via secret manager, never hardcode.","Pin api_base to the exact MiniMax TTS endpoint when self-configuring.","Enable litellm verbose logging in staging to capture raw upstream bodies."],"tags":["minimax","text-to-speech","json-parse","api-key","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}