Skip to content

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

Open
@Mikaeldsouza

Description

@Mikaeldsouza

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions