{"record":{"id":"4559687e8672a75b","repo":"BerriAI/litellm","slug":"error-receiving-chunk-from-stream-e-455968","errorCode":null,"errorMessage":"Error receiving chunk from stream: {e}","messagePattern":"Error receiving chunk from stream: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"litellm/llms/cohere/common_utils.py","lineNumber":170,"sourceCode":"                provider_specific_fields=provider_specific_fields,\n            )\n\n            return returned_chunk\n\n        except json.JSONDecodeError:\n            raise ValueError(f\"Failed to decode JSON from chunk: {chunk}\")\n\n    # Sync iterator\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        try:\n            chunk: Final = self.response_iterator.__next__()\n        except StopIteration:\n            raise StopIteration\n        except ValueError as e:\n            raise RuntimeError(f\"Error receiving chunk from stream: {e}\")\n\n        try:\n            return self.convert_str_chunk_to_generic_chunk(chunk=chunk)\n        except StopIteration:\n            raise StopIteration\n        except ValueError as e:\n            raise RuntimeError(f\"Error parsing chunk: {e},\\nReceived chunk: {chunk}\")\n\n    def convert_str_chunk_to_generic_chunk(self, chunk: str) -> GenericStreamingChunk:\n        \"\"\"\n        Convert a string chunk to a GenericStreamingChunk\n\n        Note: This is used for Cohere pass through streaming logging\n        \"\"\"\n        str_line = chunk\n        if isinstance(chunk, bytes):  # Handle binary data\n            str_line = chunk.decode(\"utf-8\")  # Convert bytes to string\n            index: Final = str_line.find(\"data:\")","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/cohere/common_utils.py#L152-L188","documentation":"The sync __next__ of the Cohere v1 streaming iterator wraps ValueError from the underlying response_iterator.__next__() as RuntimeError('Error receiving chunk from stream: {e}'). This fires when pulling the next raw chunk itself raises a ValueError (transport/decoding error inside httpx iteration), before LiteLLM's own chunk parsing runs.","triggerScenarios":"Synchronous streaming iteration over a Cohere response where the underlying httpx line iterator raises ValueError while reading — e.g. malformed chunked transfer encoding or decode errors in the byte stream — as distinct from a chunk that parses but is invalid JSON (that path yields 'Error parsing chunk' instead).","commonSituations":"Interrupted streams (client disconnects mid-read), proxies mangling chunked encoding, rare httpx decoding edge cases. Usually transient; persistent occurrence points at a broken network path.","solutions":["Distinguish the two messages: 'Error receiving chunk' = transport-level; 'Error parsing chunk' = content-level — fix accordingly.","Retry the streaming request with backoff for transient transport faults.","Bypass proxies/VPNs between the runtime and api.cohere.com if corruption persists.","Fall back to a non-streaming call to retrieve the full response when streaming reliability is unacceptable."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    for chunk in stream:\n        consume(chunk)\nexcept RuntimeError as e:\n    if \"Error receiving chunk from stream\" in str(e):\n        backoff_and_retry_stream()  # transport-level, worth retrying\n    raise","preventionTips":["Set adequate read timeouts so long generations are not cut mid-stream.","Distinguish 'receiving' (transport) from 'parsing' (content) in your error handler to route to the right fix.","Add a non-streaming fallback path for reliability-critical flows."],"tags":["cohere","streaming","sync","transport"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}