{"record":{"id":"e77a6286ab63a0bd","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-complete-the-chat","errorCode":null,"errorMessage":"{type(self)} service failed to complete the chat","messagePattern":"(.+?) service failed to complete the chat","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/nvidia/services/nvidia_handler.py","lineNumber":80,"sourceCode":"\n    async def _send_chat_completion_request(\n        self, settings: NvidiaChatPromptExecutionSettings\n    ) -> ChatCompletion | AsyncStream[Any]:\n        \"\"\"Send a request to the NVIDIA chat completion endpoint.\"\"\"\n        try:\n            settings_dict = settings.prepare_settings_dict()\n\n            # Handle structured output if nvext is present in extra_body\n            if settings.extra_body and \"nvext\" in settings.extra_body:\n                if \"extra_body\" not in settings_dict:\n                    settings_dict[\"extra_body\"] = {}\n                settings_dict[\"extra_body\"][\"nvext\"] = settings.extra_body[\"nvext\"]\n\n            response = await self.client.chat.completions.create(**settings_dict)\n            self.store_usage(response)\n            return response\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the chat\",\n                ex,\n            ) from ex\n\n    def store_usage(\n        self,\n        response: ChatCompletion\n        | Completion\n        | AsyncStream[ChatCompletionChunk]\n        | AsyncStream[Completion]\n        | CreateEmbeddingResponse,\n    ):\n        \"\"\"Store the usage information from the response.\"\"\"\n        if not isinstance(response, AsyncStream) and response.usage:\n            logger.info(f\"OpenAI usage: {response.usage}\")\n            self.prompt_tokens += response.usage.prompt_tokens\n            self.total_tokens += response.usage.total_tokens\n            if hasattr(response.usage, \"completion_tokens\"):","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/nvidia/services/nvidia_handler.py#L62-L98","documentation":"Raised as ServiceResponseException (chaining `ex`) when `self.client.chat.completions.create(**settings_dict)` throws any exception in `NvidiaHandler._send_chat_completion_request`. The block also merges settings.extra_body['nvext'] into the request for NVIDIA structured output, so a malformed nvext can contribute. The true upstream error is in `ex`/`__cause__`.","triggerScenarios":"NVIDIA chat completion where the OpenAI-style client raises: 401 auth, 404 unknown model, 400/422 from unsupported params or a malformed nvext extra_body, 429 rate limit, or network/timeout. Also if settings_dict contains keys the NVIDIA endpoint rejects.","commonSituations":"ai_model_id not deployed on the NVIDIA endpoint, passing OpenAI-specific params NVIDIA rejects, malformed structured-output nvext payload, expired NVIDIA_API_KEY, transient rate limit.","solutions":["Inspect `e.__cause__` for the exact upstream status/message.","Verify ai_model_id is a valid model id for the NVIDIA base_url endpoint.","If using extra_body/nvext structured output, validate its shape matches NVIDIA's nvext schema; remove it to isolate the cause.","Strip unsupported params from the request or move them into extra_body.","Retry on 429/timeout; confirm NVIDIA_API_KEY validity."],"exampleFix":"# before\nresp = await svc.get_chat_message_contents(chat_history, settings)\n\n# after\ntry:\n    resp = await svc.get_chat_message_contents(chat_history, settings)\nexcept ServiceResponseException as e:\n    raise RuntimeError(f\"NVIDIA chat upstream error: {e.__cause__!r}\") from e","handlingStrategy":"try-catch","validationCode":"assert svc.ai_model_id, 'ai_model_id must be set for NVIDIA chat'\nif getattr(settings, 'extra_body', None) and 'nvext' in settings.extra_body:\n    assert isinstance(settings.extra_body['nvext'], dict), 'nvext must be a dict'","typeGuard":"from semantic_kernel.exceptions import ServiceResponseException\n\ndef is_nvidia_chat_error(e: BaseException) -> bool:\n    return isinstance(e, ServiceResponseException) and 'failed to complete the chat' in str(e)","tryCatchPattern":"from semantic_kernel.exceptions import ServiceResponseException\ntry:\n    resp = await svc.get_chat_message_contents(chat_history, settings)\nexcept ServiceResponseException as e:\n    cause = e.__cause__\n    raise RuntimeError(f'NVIDIA chat upstream error: {cause!r}') from cause","preventionTips":["Validate ai_model_id is deployed on the NVIDIA endpoint before calling.","If using nvext structured output, validate its dict shape first; isolate by removing it on error.","Strip OpenAI-specific params NVIDIA does not accept.","Retry transient 429/timeout; verify NVIDIA_API_KEY validity."],"tags":["nvidia","chat-completion","network","api-key","structured-output","service-response-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}