{"record":{"id":"2b75b5b5791ecf61","repo":"BerriAI/litellm","slug":"unmapped-response-type-got-type-type-result","errorCode":null,"errorMessage":"Unmapped response type. Got type: {type(result)}","messagePattern":"Unmapped response type\\. Got type: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/endpoints/speech/speech_to_completion_bridge/handler.py","lineNumber":123,"sourceCode":"            input=input,\n            optional_params=optional_params,\n            litellm_params=litellm_params,\n            headers=headers,\n            litellm_logging_obj=logging_obj,\n            custom_llm_provider=custom_llm_provider,\n            voice=voice,\n        )\n\n        result: Final = completion(\n            **request_data,\n        )\n\n        if isinstance(result, ModelResponse):\n            return self.transformation_handler.transform_response(\n                model_response=result,\n            )\n        else:\n            raise Exception(f\"Unmapped response type. Got type: {type(result)}\")\n\n\nspeech_to_completion_bridge_handler = SpeechToCompletionBridgeHandler()\n","sourceCodeStart":105,"sourceCodeEnd":127,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/endpoints/speech/speech_to_completion_bridge/handler.py#L105-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove/override stream for speech calls: pass litellm_params without stream, or explicitly stream=False.","Verify you are calling litellm.speech() (the bridge path) with a standard provider that returns ModelResponse.","In tests, patch completion to return a real ModelResponse with message.audio set."],"exampleFix":"# before: stream leaks into the bridged completion -> generator, not ModelResponse\nresp = litellm.speech(model=\"openai/gpt-4o-audio-preview\", input=\"hi\", voice=\"alloy\")  # with router default stream=True\n\n# after: force non-streaming for TTS\nresp = litellm.speech(model=\"openai/gpt-4o-audio-preview\", input=\"hi\", voice=\"alloy\", stream=False)","handlingStrategy":"try-catch","validationCode":"def sanitize_speech_litellm_params(litellm_params: dict) -> dict:\n    \"\"\"The bridge needs a full ModelResponse; strip streaming before it forwards to completion().\"\"\"\n    cleaned = dict(litellm_params)\n    cleaned.pop(\"stream\", None)\n    cleaned[\"stream\"] = False\n    return cleaned","typeGuard":null,"tryCatchPattern":"try:\n    audio = litellm.speech(model=model, input=text, voice=voice)\nexcept Exception as e:\n    if \"Unmapped response type\" in str(e):\n        raise RuntimeError(\n            f\"speech bridge got a non-ModelResponse (check stream=True leaking into litellm_params \"\n            f\"or a non-standard provider config): {e}\"\n        ) from e\n    raise","preventionTips":["Never enable stream for TTS/speech calls — the bridge must buffer the full response to decode audio.","Audit router/proxy defaults that inject stream=True globally and exclude speech routes.","In tests, patch litellm.completion to return a real ModelResponse with message.audio set."],"tags":["speech","tts","response-type","streaming","internal-api"],"backgroundTag":"unexpected-response-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}