Skip to content

Async example in streaming documentation is missing await and async for #2297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
Mikaeldsouza opened this issue Apr 10, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@Mikaeldsouza
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Hi,

I noticed a small but important issue in the streaming responses documentation, specifically in the async example.

In the async version of the streaming code, the following two issues appear:

  1. The call to client.responses.create(...) is missing an await.
  2. The loop over the stream uses for instead of async for.

Current code:
async def main(): stream = client.responses.create(...) # Missing 'await' for event in stream: # Should be 'async for' print(event)

Suggested fix:
async def main():
stream = await client.responses.create(...)
async for event in stream:
print(event)

To Reproduce

  1. Copy the async streaming example from the documentation: streaming responses documentation
  2. Run the script using Python 3.8+ with the latest openai package installed.

Code snippets

OS

any

Python version

Python 3.8+

Library version

v1.72.0

@Mikaeldsouza Mikaeldsouza added the bug Something isn't working label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant