{"record":{"id":"39d6ffa49d431db8","repo":"BerriAI/litellm","slug":"file-content-stream-does-not-support-sync-iteratio","errorCode":null,"errorMessage":"File content stream does not support sync iteration","messagePattern":"File content stream does not support sync iteration","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"litellm/files/streaming.py","lineNumber":49,"sourceCode":"        self.stream_iterator = stream_iterator\n        self.file_id = file_id\n        self.model = model\n        self.custom_llm_provider = custom_llm_provider\n        self.logging_obj = logging_obj\n        self.standard_logging_object: StandardLoggingPayload | None = None\n        self._hidden_params: dict[str, Any] = {}\n        self._logging_completed = False\n        self._close_completed = False\n        self._start_time = (\n            logging_obj.start_time\n            if logging_obj is not None and getattr(logging_obj, \"start_time\", None)\n            else datetime.datetime.now()\n        )\n        self._sync_hidden_params()\n\n    def __iter__(self) -> \"FileContentStreamingResponse\":\n        if not hasattr(self.stream_iterator, \"__next__\"):\n            raise TypeError(\"File content stream does not support sync iteration\")\n        return self\n\n    def __next__(self) -> bytes:\n        if not hasattr(self.stream_iterator, \"__next__\"):\n            raise TypeError(\"File content stream does not support sync iteration\")\n\n        try:\n            return next(cast(Iterator[bytes], self.stream_iterator))\n        except StopIteration:\n            self._log_success_sync()\n            raise\n        except Exception as e:\n            self._log_failure_sync(e)\n            raise\n\n    def __aiter__(self) -> \"FileContentStreamingResponse\":\n        if not hasattr(self.stream_iterator, \"__anext__\"):\n            raise TypeError(\"File content stream does not support async iteration\")","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/files/streaming.py#L31-L67","documentation":"FileContentStreamingResponse was used as a sync iterator but the underlying stream_iterator only supports async iteration; the guard fires before any bytes are pulled so logging state stays consistent.","triggerScenarios":"Thrown at litellm/files/streaming.py:49 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use async iteration (async for) on this file content stream, or read the full content at once.","Do not call synchronous iteration methods on an async-only stream."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}