openai/openai-python · error · ValueError

id must be provided when streaming an existing response

Error message

id must be provided when streaming an existing response

What it means

Raised by Responses.stream() when neither new-response arguments nor a response_id are given. To stream, you must either create a new response (input+model) or resume streaming an existing one by id; the SDK enforces this fork client-side.

Source

Thrown at src/openai/resources/responses/responses.py:1284

                top_p=top_p,
                truncation=truncation,
                user=user,
                background=background,
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
            )

            return ResponseStreamManager(
                api_request,
                text_format=text_format,
                input_tools=tools,
                starting_after=None,
            )
        else:
            if not is_given(response_id):
                raise ValueError("id must be provided when streaming an existing response")

            return ResponseStreamManager(
                lambda: self.retrieve(
                    response_id=response_id,
                    stream=True,
                    include=include or [],
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    starting_after=omit,
                    timeout=timeout,
                ),
                text_format=text_format,
                input_tools=tools,
                starting_after=starting_after if is_given(starting_after) else None,
            )

    def parse(

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass the id of an existing response: client.responses.stream(response_id='resp_abc')
  2. Or provide input and model to create and stream a new response
  3. Check that the variable holding the id is not None before calling stream()

Example fix

// before
client.responses.stream()  # nothing given
// after
client.responses.stream(response_id="resp_abc")
Defensive patterns

Strategy: validation

Validate before calling

from openai._utils import is_given
if not is_given(response_id) and not any(is_given(v) for k, v in kwargs.items() if k in CREATE_ARGS):
    raise ValueError('provide either response_id or input+model to stream()')

Type guard

def can_stream(response_id, input, model) -> bool:
    return (isinstance(response_id, str) and response_id) or (bool(input) and bool(model))

Try / catch

try:
    with client.responses.stream(...) as s:
        ...
except ValueError as e:
    if 'streaming an existing response' in str(e):
        s = client.responses.stream(response_id=stored_id)
    else:
        raise

Prevention

When it happens

Trigger: Calling client.responses.stream() with no create arguments and no response_id, e.g. client.responses.stream(stream=True) or all arguments defaulted/NotGiven.

Common situations: Passing response_id=None from a variable that was never populated (e.g. upstream response object missing .id); building a generic wrapper that conditionally streams and forgetting to forward the id.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/694263126871898c. Report an issue: GitHub.