Closed
Description
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
The current code example in README.md
for streaming responses with the async client will raise an exception because it is missing an await
and should use async for
instead of for
.
Current example:
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI()
async def main():
stream = client.responses.create(
model="gpt-4o",
input="Write a one-sentence bedtime story about a unicorn.",
stream=True,
)
for event in stream:
print(event)
asyncio.run(main())
This will raise an exception.
It should be:
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI()
async def main():
stream = await client.responses.create(
model="gpt-4o",
input="Write a one-sentence bedtime story about a unicorn.",
stream=True,
)
async for event in stream:
print(event)
asyncio.run(main())