{"record":{"id":"d37a7c30c0ca7130","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-complete-the-reques","errorCode":null,"errorMessage":"{type(self)} service failed to complete the request","messagePattern":"(.+?) service failed to complete the request","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py","lineNumber":334,"sourceCode":"                metadata = metadata | {\"usage\": metadata.get(\"usage\", {}) | {\"output_tokens\": output_tokens}}\n\n        return StreamingChatMessageContent(\n            choice_index=0,\n            inner_content=stream_event,\n            ai_model_id=self.ai_model_id,\n            metadata=metadata,\n            role=AuthorRole.ASSISTANT,\n            finish_reason=finish_reason,\n            items=items,\n            function_invoke_attempt=function_invoke_attempt,\n        )\n\n    async def _send_chat_request(self, settings: AnthropicChatPromptExecutionSettings) -> list[\"ChatMessageContent\"]:\n        \"\"\"Send the chat request.\"\"\"\n        try:\n            response = await self.async_client.messages.create(**settings.prepare_settings_dict())\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the request\",\n                ex,\n            ) from ex\n\n        response_metadata: dict[str, Any] = {\"id\": response.id}\n        if hasattr(response, \"usage\") and response.usage is not None:\n            response_metadata[\"usage\"] = response.usage\n\n        return [self._create_chat_message_content(response, response_metadata)]\n\n    async def _send_chat_stream_request(\n        self,\n        settings: AnthropicChatPromptExecutionSettings,\n        function_invoke_attempt: int = 0,\n    ) -> AsyncGenerator[list[\"StreamingChatMessageContent\"], None]:\n        \"\"\"Send the chat stream request.\n\n        The stream yields a sequence of stream events, which are used to create streaming chat message content:","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/anthropic/services/anthropic_chat_completion.py#L316-L352","documentation":"Wraps any exception thrown by the Anthropic SDK's async_client.messages.create(...) during a non-streaming chat request. ServiceResponseException is a generic transport/API-level failure carrier; the original exception is chained via 'from ex' and passed as a second argument so callers can inspect the underlying AnthropicError (auth, rate limit, overload, invalid_request, etc.).","triggerScenarios":"Any failure in the HTTP call to the Anthropic Messages endpoint: expired/invalid API key (AuthenticationError), 429 rate limiting, 529 overloaded, malformed request_body from settings.prepare_settings_dict(), network timeout, or SDK internal errors.","commonSituations":"Wrong/expired ANTHROPIC_API_KEY or Anthropic settings; hitting token-per-minute or request-per-minute quotas; sending more max_tokens than the model allows; model_id typo or access to a model not enabled for the key; transient network issues or Anthropic-side outages (529).","solutions":["Inspect the chained exception (ex / __cause__) to identify the Anthropic error type and act on it (re-auth, back off, fix payload).","For 429/529: implement exponential backoff with jitter and retry; consider reducing request frequency or upgrading rate limits.","Verify ANTHROPIC_API_KEY is set and valid, the model_id is correct and accessible, and settings.prepare_settings_dict() produces a valid payload.","For network timeouts, configure HTTP retries/timeouts on the async client."],"exampleFix":"from semantic_kernel.exceptions import ServiceResponseException\n\ntry:\n    result = await service.get_chat_message_contents(history=history, settings=settings)\nexcept ServiceResponseException as e:\n    cause = e.__cause__\n    print(type(cause), cause)","handlingStrategy":"retry","validationCode":"from semantic_kernel.exceptions import ServiceResponseException\n\n# Pre-flight: basic payload sanity (cannot fully prevent transient/network errors)\nassert settings.model_id, \"model_id must be set\"\nassert history and len(history) > 0, \"history must not be empty\"","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResponseException\nimport asyncio\n\nasync def call_with_retry(service, history, settings, attempts=4):\n    for attempt in range(attempts):\n        try:\n            return await service.get_chat_message_contents(history=history, settings=settings)\n        except ServiceResponseException as e:\n            cause = e.__cause__\n            name = type(cause).__name__ if cause else \"\"\n            if name in {\"RateLimitError\", \"APIStatusError\", \"OverloadedError\"} and attempt < attempts - 1:\n                await asyncio.sleep(2 ** attempt)\n                continue\n            raise","preventionTips":["Verify ANTHROPIC_API_KEY and model_id before the call.","Cap max_tokens within model limits in settings.","Inspect __cause__ to distinguish auth/payload/transient failures."],"tags":["anthropic","network","api-error","retry","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}