Skip to content

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

Closed
nightcityblade wants to merge 1 commit into
openai:mainfrom
nightcityblade:fix/issue-2853
Closed

nightcityblade wants to merge 1 commit into
openai:mainfrom
nightcityblade:fix/issue-2853

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

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
@nightcityblade

Copy link
Copy Markdown
Contributor Author

Gentle ping — this adds the missing aclose() method to AsyncStream for proper PEP 525 async generator cleanup. Happy to address any feedback.

Copy link
Copy Markdown
Contributor

Thanks for the contribution, and sorry for the delay! This is now covered by #2854, so I’m closing this PR.

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

2 participants