openai/openai-python · error · ValueError

Expected a non-empty value for `response_id` but received {r

Error message

Expected a non-empty value for `response_id` but received {response_id!r}

What it means

The sync beta Responses input_items list method requires a non-empty `response_id` for the URL `/responses/{response_id}/input_items?beta=true`. The guard raises ValueError locally for falsy values.

Source

Thrown at src/openai/resources/beta/responses/input_items.py:87

          limit: A limit on the number of objects to be returned. Limit can range between 1 and
              100, and the default is 20.

          order: The order to return the input items in. Default is `desc`.

              - `asc`: Return the input items in ascending order.
              - `desc`: Return the input items in descending order.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if not response_id:
            raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
        extra_headers = {
            **strip_not_given({"openai-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
            **(extra_headers or {}),
        }
        return self._get_api_list(
            path_template("/responses/{response_id}/input_items?beta=true", response_id=response_id),
            page=SyncCursorPage[BetaResponseItem],
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "after": after,
                        "include": include,
                        "limit": limit,
                        "order": order,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Use the `id` field from the response object returned by create
  2. Validate response_id is a non-empty 'resp_...' string before calling
  3. Store response IDs when created if you need to list items later

Example fix

// before
items = client.beta.responses.input_items.list(response_id="")
// after
items = client.beta.responses.input_items.list(response_id=response.id)
Defensive patterns

Strategy: validation

Validate before calling

if not response_id:
    raise ValueError("response_id required to list input items")

Type guard

def is_valid_response_id(v: object) -> bool:
    return isinstance(v, str) and bool(v.strip()) and v.startswith("resp_")

Try / catch

try:
    items = client.beta.responses.input_items.list(response_id=rid)
except ValueError:
    raise

Prevention

When it happens

Trigger: Calling `client.beta.responses.input_items.list(response_id="")` or None on the sync client (input_items.py:87).

Common situations: Inspecting input items for a response whose ID wasn't captured from the create/stream result; passing a model name instead of a response ID.

Related errors


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