BerriAI/litellm · error · MinimaxException

Failed to parse MiniMax response: {e}

Error message

Failed to parse MiniMax response: {e}

What it means

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.

Source

Thrown at litellm/llms/minimax/text_to_speech/transformation.py:379

            # We need to create a response that contains the decoded audio bytes
            # Remove gzip encoding headers to avoid decompression issues
            clean_headers: Final = dict(raw_response.headers)
            clean_headers.pop("content-encoding", None)
            clean_headers.pop("transfer-encoding", None)
            clean_headers["content-length"] = str(len(audio_bytes))

            # Create a new response object with the binary content
            binary_response: Final = httpx.Response(
                status_code=200,
                headers=clean_headers,
                content=audio_bytes,
                request=raw_response.request,
            )

            return HttpxBinaryResponseContent(binary_response)

        except json.JSONDecodeError as e:
            raise MinimaxException(
                status_code=500,
                message=f"Failed to parse MiniMax response: {e}",
                headers=dict(raw_response.headers),
            )
        except Exception as e:
            if isinstance(e, MinimaxException):
                raise
            raise MinimaxException(
                status_code=500,
                message=f"Error processing MiniMax response: {e}",
                headers=dict(raw_response.headers),
            )

    def get_complete_url(
        self,
        model: str,
        api_base: str | None,
        litellm_params: dict,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Verify MINIMAX_API_KEY (or the api_key param) is set and valid for the MiniMax TTS platform.
  2. Check api_base — it must be the real MiniMax TTS endpoint, not a web page or generic MiniMax chat host.
  3. Log raw_response.text (via litellm verbose logs or a proxy hook) to see the actual non-JSON body returned upstream.
  4. Confirm the model name is a MiniMax TTS model (e.g. speech-01-hd/turbo) supported by the endpoint.
  5. Retry once after fixing config; if upstream is flaky, wrap the call in a retry with backoff.

Example fix

# before
resp = litellm.text_to_speech(model="minimax/tts-01", input="hi")

# after — explicit key + base and a readable failure
import litellm
resp = litellm.text_to_speech(
    model="minimax/tts-02-hd-preview",
    input="hello world",
    api_key=os.environ["MINIMAX_API_KEY"],          # fail fast if unset
    api_base="https://api.minimax.chat/v1/t2a_v2",  # exact TTS endpoint
)
Defensive patterns

Strategy: try-catch

Validate before calling

import os
assert os.getenv("MINIMAX_API_KEY"), "MINIMAX_API_KEY must be set before calling MiniMax TTS"

Try / catch

from litellm.exceptions import APIError
try:
    audio = litellm.text_to_speech(model="minimax/tts-02-hd-preview", input=text)
except APIError as e:
    if "Failed to parse MiniMax response" in str(e):
        # non-JSON upstream body: inspect key/base, do not blind-retry
        raise RuntimeError(f"MiniMax returned non-JSON body (check api_key/api_base): {e}") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/95532ce9c03b74a1. Report an issue: GitHub.