BerriAI/litellm · error · ValueError
Failed to convert ModelResponse to ModelResponseStream
Error message
Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e} What it means
Error "Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e}" thrown in BerriAI/litellm.
Solutions
- Inspect the ModelResponse in the error; it cannot be converted to a stream chunk. Check the provider response shape.
When it happens
Trigger: Thrown at litellm/llms/base_llm/base_model_iterator.py:63 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/9f854ba90da6cb90.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/base_llm/base_model_iterator.py:63
),
finish_reason=choice.finish_reason,
)
)
processed_chunk: Final = ModelResponseStream(
id=model_response.id,
object="chat.completion.chunk",
created=model_response.created,
model=model_response.model,
choices=streaming_choices,
)
# Carry usage onto the streaming chunk so fake-streamed responses
# (e.g. Vertex AI Gemma :predict) still report token counts.
usage: Final = getattr(model_response, "usage", None)
if usage is not None:
setattr(processed_chunk, "usage", usage)
return processed_chunk
except Exception as e:
raise ValueError(f"Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e}")
class BaseModelResponseIterator:
def __init__(self, streaming_response, sync_stream: bool, json_mode: bool | None = False):
self.streaming_response = streaming_response
self.response_iterator = self.streaming_response
self.json_mode = json_mode
self.http_response: httpx.Response | None = None
async def aclose(self) -> None:
"""Close the upstream HTTP response so the provider connection is
released (and a backend like vLLM aborts generation) when the stream
is abandoned before its natural end.
``streaming_response`` is usually a bare ``aiter_lines()`` generator
that holds no reference to the response, so the handler that owns the
response attaches it here after construction."""
if self.http_response is not None:View on GitHub (pinned to 77b7c6c40c)