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 client.responses.retrieve() when response_id is empty (None, '', or falsy) before any HTTP request is made. The id is interpolated into the path /responses/{response_id}, so an empty value would produce a malformed URL; the SDK fails fast instead.
Source
Thrown at src/openai/resources/responses/responses.py:1626
...
def retrieve(
self,
response_id: str,
*,
include: List[ResponseIncludable] | Omit = omit,
include_obfuscation: bool | Omit = omit,
starting_after: int | Omit = omit,
stream: Literal[False] | Literal[True] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> Response | Stream[ResponseStreamEvent]:
if not response_id:
raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}")
return self._get(
path_template("/responses/{response_id}", response_id=response_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"include": include,
"include_obfuscation": include_obfuscation,
"starting_after": starting_after,
"stream": stream,
},
response_retrieve_params.ResponseRetrieveParams,
),
security={"bearer_auth": True},
),View on GitHub (pinned to 9917c6e28e)
Solutions
- Verify the id is a non-empty string starting with 'resp_' before calling retrieve
- Trace where response_id came from — usually a previous response object or stored job id
- If reading from storage/API output, add a guard clause for falsy values
Example fix
// before
resp = client.responses.retrieve(response_id=data.get("id"))
// after
rid = data.get("id") or ""
resp = client.responses.retrieve(response_id=rid) if rid else None Defensive patterns
Strategy: validation
Validate before calling
rid = response_id if isinstance(response_id, str) and response_id.strip() else None
if not rid:
raise ValueError(f'cannot retrieve response with empty id: {response_id!r}')
resp = client.responses.retrieve(response_id=rid) Type guard
def is_valid_response_id(rid) -> bool:
return isinstance(rid, str) and bool(rid.strip()) Try / catch
try:
resp = client.responses.retrieve(response_id=rid)
except ValueError as e:
if 'non-empty value' in str(e):
rid = fallback_id or fetch_latest_id()
if rid:
resp = client.responses.retrieve(response_id=rid)
else:
raise
else:
raise Prevention
- Guard all retrieve calls with a truthiness check on the id
- Validate ids parsed from external payloads (webhooks, DB rows)
- Log when an expected id is missing rather than passing it through
When it happens
Trigger: client.responses.retrieve(response_id=None), retrieve(''), or retrieve(response_id='') where the id came from an unset variable or a response object whose .id was missing/empty.
Common situations: Accessing response.id on an object that doesn't have it (e.g. an error object or a stream event), passing an empty string from parsed JSON, typos like response_id='' defaults in wrappers.
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
- Expected a non-empty value for `response_id` but received {r
- Expected a non-empty value for `response_id` but received {r
- model must be provided when creating a new response
- id must be provided when streaming an existing response
- Pagination is only supported with mappings
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/1c691009edae9025.
Report an issue: GitHub.