BerriAI/litellm · error · RuntimeError
Error parsing chunk: {e},\nReceived chunk: {chunk}
Error message
Error parsing chunk: {e},\nReceived chunk: {chunk} What it means
Except-handler in ModelResponseIterator chunk parsing: _common_chunk_parsing_logic raised while transforming the raw chunk into a ModelResponse; both the exception and the offending chunk are embedded so the malformed payload can be inspected.
Source
Thrown at litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py:3367
def __next__(self):
try:
chunk: Final = self.response_iterator.__next__()
except StopIteration:
if self.chunk_type == "accumulated_json" and self.accumulated_json:
result: Final = self.handle_accumulated_json_chunk(chunk="", is_final=True)
if result is not None:
return result
raise StopIteration
except ValueError as e:
raise RuntimeError(f"Error receiving chunk from stream: {e}")
try:
return self._common_chunk_parsing_logic(chunk=chunk)
except StopIteration:
raise StopIteration
except ValueError as e:
raise RuntimeError(f"Error parsing chunk: {e},\nReceived chunk: {chunk}")
# Async iterator
def __aiter__(self):
self.async_response_iterator = self.streaming_response.__aiter__()
return self
async def __anext__(self):
try:
chunk: Final = await self.async_response_iterator.__anext__()
except StopAsyncIteration:
if self.chunk_type == "accumulated_json" and self.accumulated_json:
result: Final = self.handle_accumulated_json_chunk(chunk="", is_final=True)
if result is not None:
return result
raise StopAsyncIteration
except ValueError as e:
raise RuntimeError(f"Error receiving chunk from stream: {e}")
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Inspect the logged chunk and parse error; the stream chunk format was unexpected.
- Check for proxy interference or an API schema change.
Example fix
# log chunk content and adapt parsing or upgrade litellm.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Triggered when parsing a Vertex AI Gemini stream chunk raises an exception.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/73c95bf2690e77e3.
Report an issue: GitHub.