Skip to content

background parameter is not being passed to create call in AsyncResponses client stream method #2579

@peterychang

Description

@peterychang

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

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