Commit 6132922c

stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
2025-10-29 18:42:58
fix(client): close streams without requiring full consumption
1 parent b16bf4e
Changed files (1)
src
src/openai/_streaming.py
@@ -96,9 +96,8 @@ class Stream(Generic[_T]):
 
                 yield process_data(data=data, cast_to=cast_to, response=response)
 
-        # Ensure the entire stream is consumed
-        for _sse in iterator:
-            ...
+        # As we might not fully consume the response stream, we need to close it explicitly
+        response.close()
 
     def __enter__(self) -> Self:
         return self
@@ -198,9 +197,8 @@ class AsyncStream(Generic[_T]):
 
                 yield process_data(data=data, cast_to=cast_to, response=response)
 
-        # Ensure the entire stream is consumed
-        async for _sse in iterator:
-            ...
+        # As we might not fully consume the response stream, we need to close it explicitly
+        await response.aclose()
 
     async def __aenter__(self) -> Self:
         return self