openai/openai-python · error · ValueError
Expected a non-empty value for `message_id` but received {me
Error message
Expected a non-empty value for `message_id` but received {message_id!r} What it means
client.beta.threads.messages.retrieve() also requires a non-empty message_id for the GET /threads/{thread_id}/messages/{message_id} path. It is validated after thread_id, so you only see this error when thread_id is valid but message_id is empty/None.
Source
Thrown at src/openai/resources/beta/threads/messages.py:149
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> Message:
"""
Retrieve a message.
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 message_id:
raise ValueError(f"Expected a non-empty value for `message_id` but received {message_id!r}")
extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
return self._get(
path_template("/threads/{thread_id}/messages/{message_id}", thread_id=thread_id, message_id=message_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=Message,
)
@typing_extensions.deprecated("The Assistants API is deprecated in favor of the Responses API")
def update(
self,
message_id: str,
*,View on GitHub (pinned to 9917c6e28e)
Solutions
- Pass the message's id: client.beta.threads.messages.retrieve(thread_id=tid, message_id=message.id)
- Double-check argument order and that the value is the id string
- Validate externally sourced ids before the call
Example fix
# before client.beta.threads.messages.retrieve(thread_id=tid, message_id="") # after client.beta.threads.messages.retrieve(thread_id=tid, message_id=message.id)
Defensive patterns
Strategy: type-guard
Validate before calling
if not (isinstance(message_id, str) and message_id):
raise ValueError("message_id must be a non-empty string") Type guard
def is_message_id(v: object) -> bool:
return isinstance(v, str) and v.startswith("msg_") and len(v) > 4 Prevention
- Pass message.id, never the Message object
- Use keyword arguments to avoid positional mix-ups
When it happens
Trigger: Calling retrieve with a valid thread_id but message_id="" or None — commonly passing the whole Message object or the thread id by mistake in the second argument.
Common situations: Argument-order mix-ups (message_id=thread_id), ids from truncated logs/URLs, or deserialized records missing the message id.
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 `thread_id` but received {thr
- Expected a non-empty value for `run_id` but received {run_id
- Expected a non-empty value for `thread_id` but received {thr
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/d2394f2611168e0b.
Report an issue: GitHub.