openai/openai-python · error · ValueError
Expected a non-empty value for `run_id` but received {run_id
Error message
Expected a non-empty value for `run_id` but received {run_id!r} What it means
The sync Runs.retrieve() method validates that `run_id` is a non-empty string (checked after `thread_id`). An empty, None, or falsy value raises ValueError before any request is sent.
Source
Thrown at src/openai/resources/beta/threads/runs/runs.py:642
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> Run:
"""
Retrieves a run.
Args:
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 thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
if not run_id:
raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
return self._get(
path_template("/threads/{thread_id}/runs/{run_id}", thread_id=thread_id, run_id=run_id),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),
cast_to=Run,
)
@typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
def update(
self,
run_id: str,
*,View on GitHub (pinned to 9917c6e28e)
Solutions
- Pass `run.id` from the created run object
- Ensure the create call completed and returned before polling
- Persist and reload both thread_id and run_id together
Example fix
// before retrieved = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id="") // after created = client.beta.threads.runs.create(thread_id=thread_id, assistant_id=assistant_id) retrieved = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=created.id)
Defensive patterns
Strategy: validation
Validate before calling
if not run_id:
raise ValueError("run_id is required to retrieve a run") Type guard
def is_valid_run_id(run_id: object) -> bool:
return isinstance(run_id, str) and run_id.startswith("run_") Try / catch
try:
run = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run_id)
except ValueError as e:
logging.warning("invalid run_id: %s", e)
raise Prevention
- Use `run.id`, not the Run object
- Await/complete create before polling
- Type-check run ids (`run_` prefix)
When it happens
Trigger: Calling `client.beta.threads.runs.retrieve(thread_id="thread_...", run_id="")` or polling with a run variable whose id is empty/None.
Common situations: Passing a Run object instead of `run.id`; polling before the create call returned (racing); run id lost during persistence/serialization between jobs.
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 `thread_id` but received {thr
- Expected a non-empty value for `thread_id` but received {thr
- Expected a non-empty value for `message_id` but received {me
- Pagination is only supported with mappings
- Expected a non-empty value for `user_id` but received {user_
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/34e909c7ef915279.
Report an issue: GitHub.