{"record":{"id":"d33f76119c4d7071","repo":"openai/openai-python","slug":"expected-a-non-empty-value-for-thread-id-but-rec-d33f76","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/threads.py","lineNumber":181,"sourceCode":"        extra_headers: Headers | None = None,\n        extra_query: Query | None = None,\n        extra_body: Body | None = None,\n        timeout: float | httpx2.Timeout | None | NotGiven = not_given,\n    ) -> Thread:\n        \"\"\"\n        Retrieves a thread.\n\n        Args:\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._get(\n            path_template(\"/threads/{thread_id}\", thread_id=thread_id),\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},\n            ),\n            cast_to=Thread,\n        )\n\n    @typing_extensions.deprecated(\"The Assistants API is deprecated in favor of the Responses API\")\n    def update(\n        self,\n        thread_id: str,\n        *,","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/beta/threads/threads.py#L163-L199","documentation":"Threads.retrieve (sync) requires a truthy thread_id path parameter for GET /threads/{thread_id}. The SDK raises ValueError client-side instead of issuing a request with an empty path segment. Truthiness check means None and \"\" (and other falsy values) are rejected.","triggerScenarios":"`client.beta.threads.retrieve(\"\")` or `client.beta.threads.retrieve(None)`; also passing a thread id variable that came back None from `client.beta.threads.create()` destructuring or a dict lookup miss.","commonSituations":"Loading a thread id from config/env/database where the field is absent, or copy-pasting example code without replacing the placeholder `thread_id_abc123`.","solutions":["Pass the real id from the create response: `thread = client.beta.threads.create()` then `client.beta.threads.retrieve(thread.id)`.","If the id comes from storage/env, validate it is a non-empty string before use.","Check for typos in the keyword argument name."],"exampleFix":"# before\nthread = client.beta.threads.retrieve(thread_id=os.getenv(\"THREAD_ID\"))\n# after\nthread_id = os.getenv(\"THREAD_ID\")\nif not thread_id:\n    raise RuntimeError(\"THREAD_ID is not set\")\nthread = client.beta.threads.retrieve(thread_id)","handlingStrategy":"validation","validationCode":"if not thread_id:\n    raise ValueError(\"thread_id must be non-empty\")\nthread = client.beta.threads.retrieve(thread_id)","typeGuard":"def is_valid_id(value: object) -> bool:\n    return isinstance(value, str) and bool(value.strip())","tryCatchPattern":"try:\n    thread = client.beta.threads.retrieve(thread_id)\nexcept ValueError as e:\n    if \"thread_id\" in str(e):\n        log.error(\"missing thread id\"); return None\n    raise","preventionTips":["Store thread.id immediately after create.","Use .get() with required-field checks when reading ids from dicts/env."],"tags":["python","openai","validation","path-parameter","threads-api"],"backgroundTag":"missing-required-parameter","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}