BerriAI/litellm · error · TypeError

File content stream does not support async iteration

Error message

File content stream does not support async iteration

What it means

Raised by FileContentStreamingResponse.__aiter__ when the wrapped stream_iterator lacks the async iteration protocol (__anext__). The underlying response only supports sync iteration, so async for-over it is rejected rather than hanging.

Solutions

  1. Use synchronous iteration on this file content stream, or read the full content at once.
  2. Do not use async for on a sync-only stream.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/files/streaming.py:67 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/37c5c98bd1b18986. Report an issue: GitHub.

Appendix: source

Thrown at litellm/files/streaming.py:67

            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")
        return self

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

        try:
            return await cast(AsyncIterator[bytes], self.stream_iterator).__anext__()
        except StopAsyncIteration:
            await self._log_success_async()
            raise
        except Exception as e:
            await self._log_failure_async(e)
            raise

    async def aclose(self) -> None:
        if self._close_completed:
            return

View on GitHub (pinned to 77b7c6c40c)