openai/openai-python · error · ValueError
Expected a non-empty value for `thread_id` but received {thr
Error message
Expected a non-empty value for `thread_id` but received {thread_id!r} What it means
The sync Runs.create() method requires a non-empty `thread_id`. The SDK raises ValueError before POSTing to /threads/{thread_id}/runs if the value is empty, None, or falsy.
Source
Thrown at src/openai/resources/beta/threads/runs/runs.py:574
model: Union[str, ChatModel, None] | Omit = omit,
parallel_tool_calls: bool | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: Optional[AssistantResponseFormatOptionParam] | Omit = omit,
stream: Optional[Literal[False]] | Literal[True] | Omit = omit,
temperature: Optional[float] | Omit = omit,
tool_choice: Optional[AssistantToolChoiceOptionParam] | Omit = omit,
tools: Optional[Iterable[AssistantToolParam]] | Omit = omit,
top_p: Optional[float] | Omit = omit,
truncation_strategy: Optional[run_create_params.TruncationStrategy] | 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,
) -> Run | Stream[AssistantStreamEvent]:
if not thread_id:
raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
return self._post(
path_template("/threads/{thread_id}/runs", thread_id=thread_id),
body=maybe_transform(
{
"assistant_id": assistant_id,
"additional_instructions": additional_instructions,
"additional_messages": additional_messages,
"instructions": instructions,
"max_completion_tokens": max_completion_tokens,
"max_prompt_tokens": max_prompt_tokens,
"metadata": metadata,
"model": model,
"parallel_tool_calls": parallel_tool_calls,
"reasoning_effort": reasoning_effort,
"response_format": response_format,
"stream": stream,
"temperature": temperature,View on GitHub (pinned to 9917c6e28e)
Solutions
- Create the thread first and pass `thread.id` to the run
- Validate `thread_id` is a non-empty string before creating the run
- If the id arrives from user input or a queue, validate it at ingestion
Example fix
// before run = client.beta.threads.runs.create(thread_id="", assistant_id=assistant_id) // after thread = client.beta.threads.create() run = client.beta.threads.runs.create(thread_id=thread.id, assistant_id=assistant_id)
Defensive patterns
Strategy: validation
Validate before calling
if not thread_id:
raise ValueError("thread_id is required to create a run") Type guard
def is_valid_thread_id(thread_id: object) -> bool:
return isinstance(thread_id, str) and bool(thread_id.strip()) Try / catch
try:
run = client.beta.threads.runs.create(thread_id=thread_id, assistant_id=assistant_id)
except ValueError as e:
logging.error("cannot start run: %s", e)
raise Prevention
- Create the thread before the run in the same function
- Pass ids explicitly between functions
- Reject empty thread ids at input boundaries
When it happens
Trigger: Calling `client.beta.threads.runs.create(thread_id="", assistant_id="asst_...")`, or passing an undefined/None thread variable when starting a run.
Common situations: Running an assistant on a thread that was never created; thread id lost between functions or tasks; using an empty string as a placeholder in scaffolding code.
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 `run_id` but received {run_id
- 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/fef3fdd3aecc47de.
Report an issue: GitHub.