Skip to content

Comments

fix: add aclose() method to AsyncStream for PEP 525 compliance#2880

Open
nightcityblade wants to merge 1 commit intoopenai:mainfrom
nightcityblade:fix/issue-2853
Open

fix: add aclose() method to AsyncStream for PEP 525 compliance#2880
nightcityblade wants to merge 1 commit intoopenai:mainfrom
nightcityblade:fix/issue-2853

Conversation

@nightcityblade
Copy link

Summary

Fixes #2853

AsyncStream only exposed close() but not aclose(), causing AttributeError when callers use the standard Python async cleanup convention (await stream.aclose()).

This surfaces in production when instrumentation libraries (e.g. Langfuse) wrap the raw stream and call aclose() following PEP 525 convention.

Fix

Add aclose() as a thin alias for close() on AsyncStream, matching the convention used by httpx.Response, asyncio.StreamWriter, and Python async generators.

Changes

  • src/openai/_streaming.py: Added aclose() method to AsyncStream class (4 lines)

AsyncStream only exposed close() but not aclose(), causing
AttributeError when callers use the standard Python async
cleanup convention (e.g. instrumentation libraries calling
response.aclose()).

Fixes openai#2853
@nightcityblade nightcityblade requested a review from a team as a code owner February 21, 2026 15:09
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