Skip to content

fix(streaming): add aclose() alias to AsyncStream#2954

Open
mvanhorn wants to merge 1 commit intoopenai:mainfrom
mvanhorn:osc/2853-asyncstream-aclose
Open

fix(streaming): add aclose() alias to AsyncStream#2954
mvanhorn wants to merge 1 commit intoopenai:mainfrom
mvanhorn:osc/2853-asyncstream-aclose

Conversation

@mvanhorn
Copy link

Fixes #2853

Problem

AsyncStream exposes close() but not aclose(), causing AttributeError when callers use the standard Python async cleanup convention (await stream.aclose()). This surfaces with instrumentation libraries (e.g. Langfuse) that wrap the raw stream.

Fix

Added aclose() as an alias for close() on AsyncStream, following the standard Python async resource convention (PEP 525, used by asyncio, httpx, etc.). Note that AsyncStream.close() already internally calls self.response.aclose().

This contribution was developed with AI assistance (Claude Code).

AsyncStream exposes close() but not aclose(), causing AttributeError
when callers use the standard Python async cleanup convention. This
surfaces with instrumentation libraries (e.g. Langfuse) that wrap
the raw stream and call aclose().

Fixes openai#2853

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncStream missing aclose() causes AttributeError in streaming structured output

1 participant