From e5617cc860862518282b0ae5f083eb8fb616382d Mon Sep 17 00:00:00 2001 From: AMATH <116212274+amathxbt@users.noreply.github.com> Date: Sat, 21 Mar 2026 23:53:22 +0100 Subject: [PATCH] fix: add missing __aiter__ method to TextGenerationStream Without __aiter__, async for chunk in stream: raises TypeError: 'TextGenerationStream' object is not an async iterable. This makes async streaming completely broken when _is_async=True. --- src/opengradient/types.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/opengradient/types.py b/src/opengradient/types.py index fa89c98..bf25053 100644 --- a/src/opengradient/types.py +++ b/src/opengradient/types.py @@ -301,6 +301,12 @@ def __iter__(self): """Iterate over stream chunks.""" return self + def __aiter__(self): + """Return async iterator (required for async for loops).""" + if not self._is_async: + raise TypeError("Use __iter__ for sync iterators") + return self + def __next__(self) -> StreamChunk: """Get next stream chunk.""" import json