{"record":{"id":"23f3b90ff50b923e","repo":"openai/openai-python","slug":"expected-a-non-empty-value-for-completion-id-but","errorCode":null,"errorMessage":"Expected a non-empty value for `completion_id` but received {completion_id!r}","messagePattern":"Expected a non-empty value for `completion_id` but received (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/resources/chat/completions/completions.py","lineNumber":1380,"sourceCode":"        extra_body: Body | None = None,\n        timeout: float | httpx2.Timeout | None | NotGiven = not_given,\n    ) -> ChatCompletion:\n        \"\"\"Get a stored chat completion.\n\n        Only Chat Completions that have been created with\n        the `store` parameter set to `true` will be returned.\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 completion_id:\n            raise ValueError(f\"Expected a non-empty value for `completion_id` but received {completion_id!r}\")\n        return self._get(\n            path_template(\"/chat/completions/{completion_id}\", completion_id=completion_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=ChatCompletion,\n        )\n\n    def update(\n        self,\n        completion_id: str,\n        *,\n        metadata: Optional[Metadata],\n        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.","sourceCodeStart":1362,"sourceCodeEnd":1398,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/chat/completions/completions.py#L1362-L1398","documentation":"ChatCompletions.retrieve (sync) requires a truthy completion_id for GET /chat/completions/{completion_id}. The SDK validates required path parameters client-side and raises ValueError for None/empty values instead of sending a malformed URL.","triggerScenarios":"`client.chat.completions.retrieve(\"\")` or passing a completion id variable that is None because the create call's response wasn't captured (`resp.id` missing) or a dict lookup failed.","commonSituations":"Storing completions for later retrieval but failing to persist `completion.id`; copy-pasting code with the placeholder `chatcmpl-abc123` left empty; passing the whole response object instead of `.id`.","solutions":["Capture the id at creation: `completion = client.chat.completions.create(...)`; store `completion.id` and pass it to retrieve.","Validate the stored id is a non-empty string before calling.","Make sure you pass `completion.id`, not the response object."],"exampleFix":"# before\nclient.chat.completions.retrieve(completion_id=\"\")\n# after\ncompletion = client.chat.completions.create(model=\"gpt-4o\", messages=[...])\nstored = completion.id\nfetched = client.chat.completions.retrieve(completion_id=stored)","handlingStrategy":"validation","validationCode":"if not completion_id:\n    raise ValueError(\"completion_id must be non-empty\")\nclient.chat.completions.retrieve(completion_id)","typeGuard":"def is_valid_id(value: object) -> bool:\n    return isinstance(value, str) and value.startswith(\"chatcmpl-\")","tryCatchPattern":null,"preventionTips":["Persist completion.id when using store=True.","Pass `.id`, never the response object, as a path parameter."],"tags":["python","openai","validation","path-parameter","chat-completions"],"backgroundTag":"missing-required-parameter","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}