From 38d96b637769a50e2e0543adf2770c1d7947ed19 Mon Sep 17 00:00:00 2001 From: Jah-yee Date: Wed, 18 Mar 2026 14:50:37 +0800 Subject: [PATCH] fix: add aclose() alias to AsyncStream - Add aclose() as an alias for close() in AsyncStream - Supports standard async resource cleanup protocol used by asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation - Brings AsyncStream to parity with callers that rely on conventional aclose() name Fixes #2982 --- src/openai/_streaming.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/openai/_streaming.py b/src/openai/_streaming.py index 45c13cc11d..d1da393123 100644 --- a/src/openai/_streaming.py +++ b/src/openai/_streaming.py @@ -238,6 +238,14 @@ async def close(self) -> None: """ await self.response.aclose() + async def aclose(self) -> None: + """ + Async close method - alias for close() to support standard async cleanup protocol. + + Used by asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation libraries. + """ + await self.close() + class ServerSentEvent: def __init__(