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

Raised by Responses.sync input_items.list() when `response_id` is empty or None. The SDK validates the path parameter before requesting /responses/{response_id}/input_items, because a blank id would hit an invalid endpoint.

Source

Thrown at src/openai/resources/responses/input_items.py:86

          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}")
        return self._get_api_list(
            path_template("/responses/{response_id}/input_items", response_id=response_id),
            page=SyncCursorPage[ResponseItem],
            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,
                    },
                    input_item_list_params.InputItemListParams,
                ),
                security={"bearer_auth": True},

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass response.id from the created Response: client.responses.input_items.list(response_id=response.id)
  2. Validate the id is a non-empty str before calling
  3. Fix variable mix-ups where the Response object (not its id) or a wrong field is passed

Example fix

# before
items = client.responses.input_items.list(response_id=resp_id or "")
# after
if not resp_id:
    raise ValueError("response_id required")
items = client.responses.input_items.list(response_id=resp_id)
Defensive patterns

Strategy: validation

Validate before calling

if not isinstance(response_id, str) or not response_id.strip():
    raise ValueError(f"invalid response_id: {response_id!r}")
client.responses.input_items.list(response_id=response_id)

Type guard

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

Try / catch

try:
    items = client.responses.input_items.list(response_id=rid)
except ValueError as e:
    logger.error("bad response_id: %s", e)

Prevention

When it happens

Trigger: client.responses.input_items.list(response_id="") or response_id=None; often from unpacking a response object whose id field was missing.

Common situations: Storing ids from truncated logs, passing the whole response object instead of response.id, or defaulting response_id to "" when no id is known yet.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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