{"record":{"id":"440b1f2436776cf4","repo":"openai/openai-python","slug":"expected-a-non-empty-value-for-thread-id-but-rec-440b1f","errorCode":null,"errorMessage":"Expected a non-empty value for `thread_id` but received {thread_id!r}","messagePattern":"Expected a non-empty value for `thread_id` but received (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/resources/beta/threads/messages.py","lineNumber":98,"sourceCode":"          attachments: A list of files attached to the message, and the tools they should be added to.\n\n          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful\n              for storing additional information about the object in a structured format, and\n              querying for objects via API or the dashboard.\n\n              Keys are strings with a maximum length of 64 characters. Values are strings with\n              a maximum length of 512 characters.\n\n          extra_headers: Send extra headers\n\n          extra_query: Add additional query parameters to the request\n\n          extra_body: Add additional JSON properties to the request\n\n          timeout: Override the client-level default timeout for this request, in seconds\n        \"\"\"\n        if not thread_id:\n            raise ValueError(f\"Expected a non-empty value for `thread_id` but received {thread_id!r}\")\n        extra_headers = {\"OpenAI-Beta\": \"assistants=v2\", **(extra_headers or {})}\n        return self._post(\n            path_template(\"/threads/{thread_id}/messages\", thread_id=thread_id),\n            body=maybe_transform(\n                {\n                    \"content\": content,\n                    \"role\": role,\n                    \"attachments\": attachments,\n                    \"metadata\": metadata,\n                },\n                message_create_params.MessageCreateParams,\n            ),\n            options=make_request_options(\n                extra_headers=extra_headers,\n                extra_query=extra_query,\n                extra_body=extra_body,\n                timeout=timeout,\n                security={\"bearer_auth\": True},","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/beta/threads/messages.py#L80-L116","documentation":"client.beta.threads.messages.create() requires a non-empty thread_id because it is a path parameter for POST /threads/{thread_id}/messages. The SDK validates this client-side and raises ValueError before making any HTTP request, since an empty id would build a malformed URL.","triggerScenarios":"Calling client.beta.threads.messages.create(thread_id=\"\", ...) or passing None/an unassigned variable as thread_id.","commonSituations":"Creating a message before creating the thread (no id yet), storing the wrong field (passing the Thread object or the message instead of thread.id), or ids loaded from empty config/env values.","solutions":["Create the thread first and pass its id: thread = client.beta.threads.create(); client.beta.threads.messages.create(thread_id=thread.id, ...)","Verify the variable actually holds a string id, not an object or None","Validate ids from external input before calling the API"],"exampleFix":"# before\nclient.beta.threads.messages.create(thread_id=\"\", content=\"hi\", role=\"user\")\n# after\nthread = client.beta.threads.create()\nclient.beta.threads.messages.create(thread_id=thread.id, content=\"hi\", role=\"user\")","handlingStrategy":"validation","validationCode":"if not thread_id:\n    raise ValueError(\"thread_id is required; create the thread first\")\nclient.beta.threads.messages.create(thread_id=thread_id, role=\"user\", content=\"hi\")","typeGuard":"def has_thread_id(t: object) -> bool:\n    return isinstance(t, str) and bool(t.strip())","tryCatchPattern":null,"preventionTips":["Create the thread before adding messages","Type thread ids as str, not Optional[str], wherever they flow"],"tags":["python","validation","required-parameter","threads","assistants"],"backgroundTag":"missing-required-parameter","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}