{"record":{"id":"5ecb20056fc06ec8","repo":"BerriAI/litellm","slug":"unexpected-responses-stream-payload","errorCode":null,"errorMessage":"Unexpected responses stream payload","messagePattern":"Unexpected responses stream payload","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/completion_extras/litellm_responses_transformation/handler.py","lineNumber":61,"sourceCode":"    def _is_preformatted_cached_chat_stream(result: Any) -> bool:\n        from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper\n\n        return isinstance(result, CustomStreamWrapper) and result.custom_llm_provider == \"cached_response\"\n\n    @staticmethod\n    def _coerce_response_object(\n        response_obj: Any,\n        hidden_params: dict | None,\n    ) -> \"ResponsesAPIResponse\":\n        if isinstance(response_obj, ResponsesAPIResponse):\n            response = response_obj\n        elif isinstance(response_obj, dict):\n            try:\n                response = ResponsesAPIResponse(**response_obj)\n            except Exception:\n                response = ResponsesAPIResponse.model_construct(**response_obj)\n        else:\n            raise ValueError(\"Unexpected responses stream payload\")\n\n        if hidden_params:\n            existing: Final = getattr(response, \"_hidden_params\", None)\n            if not isinstance(existing, dict) or not existing:\n                setattr(response, \"_hidden_params\", dict(hidden_params))\n            else:\n                for key, value in hidden_params.items():\n                    existing.setdefault(key, value)\n        return response\n\n    def _collect_response_from_stream(self, stream_iter: Any) -> \"ResponsesAPIResponse\":\n        for _ in stream_iter:\n            pass\n\n        completed: Final = getattr(stream_iter, \"completed_response\", None)\n        response_obj: Final = getattr(completed, \"response\", None) if completed else None\n        if response_obj is None:\n            raise ValueError(\"Stream ended without a completed response\")","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/completion_extras/litellm_responses_transformation/handler.py#L43-L79","documentation":"Coercion helper in the Responses-transformation handler received a stream payload whose shape it cannot convert into a ResponsesAPIResponse — neither a pre-built response object nor a recognizable dict — indicating an unexpected provider/stream format.","triggerScenarios":"Thrown at litellm/completion_extras/litellm_responses_transformation/handler.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that the upstream provider stream returns well-formed responses API events; the payload received did not match the expected schema.","Enable debug logging (litellm.set_verbose=True) to inspect the raw stream payload and report the unexpected event shape."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}