BerriAI/litellm · error · TypeError

File content stream does not support sync iteration

Error message

File content stream does not support sync iteration

What it means

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.

Solutions

  1. Use async iteration (async for) on this file content stream, or read the full content at once.
  2. Do not call synchronous iteration methods on an async-only stream.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/files/streaming.py:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/39d6ffa49d431db8. Report an issue: GitHub.

Appendix: source

Thrown at litellm/files/streaming.py:49

        self.stream_iterator = stream_iterator
        self.file_id = file_id
        self.model = model
        self.custom_llm_provider = custom_llm_provider
        self.logging_obj = logging_obj
        self.standard_logging_object: StandardLoggingPayload | None = None
        self._hidden_params: dict[str, Any] = {}
        self._logging_completed = False
        self._close_completed = False
        self._start_time = (
            logging_obj.start_time
            if logging_obj is not None and getattr(logging_obj, "start_time", None)
            else datetime.datetime.now()
        )
        self._sync_hidden_params()

    def __iter__(self) -> "FileContentStreamingResponse":
        if not hasattr(self.stream_iterator, "__next__"):
            raise TypeError("File content stream does not support sync iteration")
        return self

    def __next__(self) -> bytes:
        if not hasattr(self.stream_iterator, "__next__"):
            raise TypeError("File content stream does not support sync iteration")

        try:
            return next(cast(Iterator[bytes], self.stream_iterator))
        except StopIteration:
            self._log_success_sync()
            raise
        except Exception as e:
            self._log_failure_sync(e)
            raise

    def __aiter__(self) -> "FileContentStreamingResponse":
        if not hasattr(self.stream_iterator, "__anext__"):
            raise TypeError("File content stream does not support async iteration")

View on GitHub (pinned to 77b7c6c40c)