BerriAI/litellm · error · ValueError

Unexpected responses stream payload

Error message

Unexpected responses stream payload

What it means

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.

Solutions

  1. Check that the upstream provider stream returns well-formed responses API events; the payload received did not match the expected schema.
  2. Enable debug logging (litellm.set_verbose=True) to inspect the raw stream payload and report the unexpected event shape.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/completion_extras/litellm_responses_transformation/handler.py:61 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/completion_extras/litellm_responses_transformation/handler.py:61

    def _is_preformatted_cached_chat_stream(result: Any) -> bool:
        from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper

        return isinstance(result, CustomStreamWrapper) and result.custom_llm_provider == "cached_response"

    @staticmethod
    def _coerce_response_object(
        response_obj: Any,
        hidden_params: dict | None,
    ) -> "ResponsesAPIResponse":
        if isinstance(response_obj, ResponsesAPIResponse):
            response = response_obj
        elif isinstance(response_obj, dict):
            try:
                response = ResponsesAPIResponse(**response_obj)
            except Exception:
                response = ResponsesAPIResponse.model_construct(**response_obj)
        else:
            raise ValueError("Unexpected responses stream payload")

        if hidden_params:
            existing: Final = getattr(response, "_hidden_params", None)
            if not isinstance(existing, dict) or not existing:
                setattr(response, "_hidden_params", dict(hidden_params))
            else:
                for key, value in hidden_params.items():
                    existing.setdefault(key, value)
        return response

    def _collect_response_from_stream(self, stream_iter: Any) -> "ResponsesAPIResponse":
        for _ in stream_iter:
            pass

        completed: Final = getattr(stream_iter, "completed_response", None)
        response_obj: Final = getattr(completed, "response", None) if completed else None
        if response_obj is None:
            raise ValueError("Stream ended without a completed response")

View on GitHub (pinned to 77b7c6c40c)