BerriAI/litellm · error · Exception

Unmapped response type. Got type

Error message

Unmapped response type. Got type: {type(result)}

What it means

After the speech bridge converts a TTS request into litellm.completion(**request_data), handler.py:118 requires the result to be a ModelResponse so it can extract message.audio. Anything else — a streaming generator (returned when stream=True is in effect), a custom response wrapper, or a patched completion — raises this generic Exception. The bridge is architecturally non-streaming: it needs the full response to decode the base64 audio payload.

Solutions

  1. Remove/override stream for speech calls: pass litellm_params without stream, or explicitly stream=False.
  2. Verify you are calling litellm.speech() (the bridge path) with a standard provider that returns ModelResponse.
  3. In tests, patch completion to return a real ModelResponse with message.audio set.

Example fix

# before: stream leaks into the bridged completion -> generator, not ModelResponse
resp = litellm.speech(model="openai/gpt-4o-audio-preview", input="hi", voice="alloy")  # with router default stream=True

# after: force non-streaming for TTS
resp = litellm.speech(model="openai/gpt-4o-audio-preview", input="hi", voice="alloy", stream=False)
Defensive patterns

Strategy: try-catch

Validate before calling

def sanitize_speech_litellm_params(litellm_params: dict) -> dict:
    """The bridge needs a full ModelResponse; strip streaming before it forwards to completion()."""
    cleaned = dict(litellm_params)
    cleaned.pop("stream", None)
    cleaned["stream"] = False
    return cleaned

Try / catch

try:
    audio = litellm.speech(model=model, input=text, voice=voice)
except Exception as e:
    if "Unmapped response type" in str(e):
        raise RuntimeError(
            f"speech bridge got a non-ModelResponse (check stream=True leaking into litellm_params "
            f"or a non-standard provider config): {e}"
        ) from e
    raise

Prevention

When it happens

Trigger: litellm_params forwarded into the bridged completion containing stream=True (transform_request spreads litellm_params verbatim, transformation.py:44), so completion returns a streaming generator instead of ModelResponse; a provider config or test double that returns a non-ModelResponse object.

Common situations: Proxy/router configurations that inject stream=True globally; users copying speech kwargs from a streaming chat integration; monkeypatched litellm.completion in tests returning Mock objects.

Related errors


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

Appendix: source

Thrown at litellm/endpoints/speech/speech_to_completion_bridge/handler.py:123

            input=input,
            optional_params=optional_params,
            litellm_params=litellm_params,
            headers=headers,
            litellm_logging_obj=logging_obj,
            custom_llm_provider=custom_llm_provider,
            voice=voice,
        )

        result: Final = completion(
            **request_data,
        )

        if isinstance(result, ModelResponse):
            return self.transformation_handler.transform_response(
                model_response=result,
            )
        else:
            raise Exception(f"Unmapped response type. Got type: {type(result)}")


speech_to_completion_bridge_handler = SpeechToCompletionBridgeHandler()

View on GitHub (pinned to 77b7c6c40c)