{"record":{"id":"e5ab0c4a398e0ace","repo":"BerriAI/litellm","slug":"an-unknown-error-occurred-with-the-stream","errorCode":null,"errorMessage":"An unknown error occurred with the stream","messagePattern":"An unknown error occurred with the stream","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/streaming_handler.py","lineNumber":1261,"sourceCode":"        elif (\n            self.custom_llm_provider and self.custom_llm_provider == \"aleph_alpha\"\n        ):  # aleph alpha doesn't provide streaming\n            response_obj = self.handle_aleph_alpha_chunk(chunk)\n            completion_obj[\"content\"] = response_obj[\"text\"]\n            if response_obj[\"is_finished\"]:\n                self.received_finish_reason = response_obj[\"finish_reason\"]\n        elif self.custom_llm_provider == \"nlp_cloud\":\n            try:\n                response_obj = self.handle_nlp_cloud_chunk(chunk)\n                completion_obj[\"content\"] = response_obj[\"text\"]\n                if response_obj[\"is_finished\"]:\n                    self.received_finish_reason = response_obj[\"finish_reason\"]\n            except Exception as e:\n                if self.received_finish_reason:\n                    raise e\n                else:\n                    if self.sent_first_chunk is False:\n                        raise Exception(\"An unknown error occurred with the stream\")\n                    self.received_finish_reason = \"stop\"\n        elif self.custom_llm_provider == \"vertex_ai\" and not isinstance(chunk, ModelResponseStream):\n            chunk = cast(Any, chunk)\n            import proto\n\n            if hasattr(chunk, \"candidates\") is True:\n                try:\n                    try:\n                        completion_obj[\"content\"] = chunk.text\n                    except Exception as e:\n                        original_exception: Final = e\n                        if \"Part has no text.\" in str(e):\n                            ## check for function calling\n                            function_call: Final = chunk.candidates[0].content.parts[0].function_call\n\n                            args_dict: Final = {}\n\n                            # Check if it's a RepeatedComposite instance","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/streaming_handler.py#L1243-L1279","documentation":"NLP Cloud branch of the main chunk dispatcher: when handle_nlp_cloud_chunk throws and no chunk was successfully emitted yet (sent_first_chunk False, no received_finish_reason), litellm cannot salvage the stream and raises this generic Exception instead of the original parse error.","triggerScenarios":"The very first NLP Cloud chunk fails to parse (auth error body, non-JSON frame) — later failures either propagate the real error or gracefully finish with 'stop', but a first-chunk failure yields this message.","commonSituations":"Invalid NLP Cloud token; model unavailable on the account; endpoint region mismatch; response format changes on NLP Cloud.","solutions":["Treat this as 'NLP Cloud stream died before producing anything' and debug credentials/model first.","Retry the request non-streaming to capture NLP Cloud's real error message.","Validate the API token and that the model supports streaming.","Wrap NLP Cloud calls with fallback provider routing."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    text = \"\".join(p for p in litellm.completion(model=\"nlp_cloud/...\", stream=True, ...))\nexcept Exception as e:\n    if \"unknown error occurred with the stream\" in str(e):\n        text = litellm.completion(model=\"nlp_cloud/...\", stream=False, ...).choices[0].message.content","preventionTips":["Keep a non-streaming fallback path for small providers.","Validate NLP Cloud credentials before starting streams."],"tags":["nlp-cloud","streaming","provider","diagnostics"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}