-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
bugSomething isn't workingSomething isn't working
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 background
parameter is not being passed through in this call
api_request = self.create( |
To Reproduce
Create a request with the client.responses.stream()
call using the AsyncClient
Attempt to retrieve the stream with a message_id and sequence_number
You should get the error
openai.BadRequestError: Error code: 400 - {'error': {'message': 'This response cannot be streamed because it was not created with background=true.', 'type': 'invalid_request_error', 'param': 'stream', 'code': 'invalid_request_error'}}
Code snippets
import asyncio
from openai import AsyncOpenAI
from openai.types.responses.response_text_delta_event import ResponseTextDeltaEvent
from openai.types.responses.response_created_event import ResponseCreatedEvent
from pydantic import BaseModel
class OutputStruct(BaseModel):
"""A structured output for testing purposes."""
___location: str
weather: str
async def main():
client = AsyncOpenAI()
input = [
{
'role': 'user',
'content': [{'type': 'input_text', 'text': 'The weather in Seattle is sunny'}]
},
{
'role': 'user',
'content': [{'type': 'input_text', 'text': 'What is the weather in Seattle?'}]
}
]
conversation_id: str | None = None
async with client.responses.stream(
model="gpt-4o",
input=input,
background=True,
store=True,
text_format=OutputStruct,
) as stream:
async for event in stream:
if isinstance(event, ResponseCreatedEvent):
conversation_id = event.response.id
if isinstance(event, ResponseTextDeltaEvent):
print(event.delta, end="", flush=True)
assert conversation_id is not None
async with client.responses.stream(
response_id=conversation_id,
text_format=OutputStruct,
starting_after=5,
) as stream:
async for event in stream:
if isinstance(event, ResponseTextDeltaEvent):
print(event.delta, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())
OS
Ubuntu
Python version
Python 3.13
Library version
openai v1.99.9
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working