BerriAI/litellm · error · ValueError

Error transforming response to json: {e}\nResponse: {raw_res

Error message

Error transforming response to json: {e}\nResponse: {raw_response.text}

What it means

WatsonX audio transcription transformation calls raw_response.json() to convert the provider response; if the body is not parseable JSON (HTML error page, empty body, SSE/text), this ValueError wraps the parse error and includes the raw text for inspection. Nothing is validated about the status code first, so non-2xx text bodies also surface here.

Source

Thrown at litellm/llms/watsonx/audio_transcription/transformation.py:173

        api_version: Final = optional_params.get("api_version", None) or litellm.WATSONX_DEFAULT_API_VERSION
        url = f"{url}?version={api_version}"

        return url

    def transform_audio_transcription_response(
        self,
        raw_response: Response,
    ) -> TranscriptionResponse:
        """
        Transform the audio transcription response from WatsonX.

        WatsonX may include a 'model' field in the response, which needs to be
        removed before creating the TranscriptionResponse object.
        """
        try:
            raw_response_json: Final = raw_response.json()
        except Exception as e:
            raise ValueError(f"Error transforming response to json: {e}\nResponse: {raw_response.text}")

        # Extract only valid fields for TranscriptionResponse.__init__()
        # TranscriptionResponse only accepts 'text' and 'usage' in __init__()
        text: Final = raw_response_json.get("text")
        usage: Final = raw_response_json.get("usage")

        # Create response with only valid fields
        response_kwargs: Final = {}
        if text is not None:
            response_kwargs["text"] = text
        if usage is not None:
            response_kwargs["usage"] = usage

        if not response_kwargs:
            raise ValueError(
                "Invalid response format. Received response does not match the expected format. Got: ",
                raw_response_json,
            )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Read the Response: text appended to the exception - it shows exactly what came back.
  2. Confirm api_base/region and credentials (WATSONX_APIKEY / token) with a direct curl to the WatsonX speech endpoint.
  3. Check HTTP proxy interference for the ibm.com host.
  4. Retry once - truncated bodies from dropped connections are often transient.

Example fix

# before (no handling)
resp = litellm.transcription(model="watsonx/whisper-large-v3", file=open("a.wav", "rb"))

# after (surface the raw body for diagnosis)
try:
    resp = litellm.transcription(model="watsonx/whisper-large-v3", file=open("a.wav", "rb"))
except ValueError as e:
    logging.error("watsonx transcription failed: %s", e)  # includes raw response text
    raise
Defensive patterns

Strategy: try-catch

Try / catch

try:
    resp = litellm.transcription(model="watsonx/whisper-large-v3", file=f)
except ValueError as e:
    if "Error transforming response to json" in str(e):
        raw = str(e).split("Response:", 1)[-1]
        logging.error("watsonx non-JSON body: %s", raw[:500])
        raise UpstreamResponseError(raw[:500]) from e
    raise

Prevention

When it happens

Trigger: litellm.transcription(model="watsonx/...", file=...) where the WatsonX endpoint replies with a non-JSON error (auth HTML, WAF page); an incorrect api_base/region URL; truncated responses on large audio uploads.

Common situations: IBM Cloud endpoints behind SSO proxies that redirect unauthenticated requests to login pages; wrong WATSONX_REGION value; network appliances truncating large multipart uploads; debugging with verbose off.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/dc5add84e88548e2. Report an issue: GitHub.