BerriAI/litellm · error · RuntimeError
Error receiving chunk from stream: {e}
Error message
Error receiving chunk from stream: {e} What it means
Raised by the sync Databricks streaming iterator when pulling the next chunk from the underlying response raises a ValueError (per the code, chiefly the JSON-decode failure from chunk_parser). The original error text is embedded in a RuntimeError, aborting iteration of the stream.
Source
Thrown at litellm/llms/databricks/streaming_utils.py:105
index=0,
)
except json.JSONDecodeError:
raise ValueError(f"Failed to decode JSON from chunk: {chunk}")
# Sync iterator
def __iter__(self):
self.response_iterator = self.streaming_response
return self
def __next__(self):
if not hasattr(self, "response_iterator"):
self.response_iterator = self.streaming_response
try:
chunk = self.response_iterator.__next__()
except StopIteration:
raise StopIteration
except ValueError as e:
raise RuntimeError(f"Error receiving chunk from stream: {e}")
try:
chunk = litellm.CustomStreamWrapper._strip_sse_data_from_chunk(chunk) or ""
chunk = chunk.strip()
if len(chunk) > 0:
json_chunk: Final = json.loads(chunk)
return self.chunk_parser(chunk=json_chunk)
else:
return GenericStreamingChunk(
text="",
is_finished=False,
finish_reason="",
usage=None,
index=0,
tool_use=None,
)
except StopIteration:
raise StopIterationView on GitHub (pinned to 6c2dcb801b)
Solutions
- Inspect the embedded inner message to find the raw chunk that failed to parse
- Add retry logic around the whole completion request for stream read failures
- Tune or disable proxy buffering/idle timeouts on the path to Databricks
- Consider non-streaming mode for unstable network paths
Example fix
# before
for chunk in response:
print(chunk)
# after
try:
for chunk in response:
print(chunk)
except RuntimeError as e:
logger.error("stream failed: %s", e)
response = litellm.completion(**params) # retry once
for chunk in response:
print(chunk) Defensive patterns
Strategy: retry
Try / catch
for attempt in range(2):
try:
response = litellm.completion(**params, stream=True)
for chunk in response:
handle(chunk)
break
except RuntimeError as e:
if attempt == 1 or "Error receiving chunk from stream" not in str(e):
raise Prevention
- Wrap sync stream consumption in a bounded retry that restarts the whole completion call
- For long streams, prefer checkpointed consumption so a retry can resume from the last handled chunk
When it happens
Trigger: Iterating a synchronous Databricks stream (for chunk in response:) where the transport raises a ValueError while reading the next SSE line — most commonly the 'Failed to decode JSON from chunk' failure propagated from the parser.
Common situations: Sync consumers of long Databricks streams through flaky proxies; streams cut mid-event by idle timeouts; partial event delivery under load.
Related errors
- Stream ended without a completed response
- chunk
- Error receiving chunk from stream: {e}
- Error receiving chunk from stream: {e}
- Error parsing chunk: {e}, Received chunk: {chunk}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/0c2f16828cc54647.
Report an issue: GitHub.