{"record":{"id":"5b1881a054d8ac13","repo":"BerriAI/litellm","slug":"str-e","errorCode":null,"errorMessage":"{str(e)}","messagePattern":"\\{str\\(e\\)\\}","errorType":"http","errorClass":"AzureOpenAIError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure/completion/handler.py","lineNumber":185,"sourceCode":"                    additional_args={\n                        \"headers\": headers,\n                        \"api_version\": api_version,\n                        \"api_base\": api_base,\n                    },\n                )\n                return openai_text_completion_config.convert_to_chat_model_response_object(\n                    response_object=TextCompletionResponse(**stringified_response),\n                    model_response_object=model_response,\n                )\n        except AzureOpenAIError as e:\n            raise e\n        except Exception as e:\n            status_code: Final = getattr(e, \"status_code\", 500)\n            error_headers = getattr(e, \"headers\", None)\n            error_response: Final = getattr(e, \"response\", None)\n            if error_headers is None and error_response:\n                error_headers = getattr(error_response, \"headers\", None)\n            raise AzureOpenAIError(status_code=status_code, message=str(e), headers=error_headers)\n\n    async def acompletion(\n        self,\n        api_key: str | None,\n        api_version: str,\n        model: str,\n        api_base: str,\n        data: dict,\n        timeout: Any,\n        model_response: ModelResponse,\n        logging_obj: Any,\n        max_retries: int,\n        azure_ad_token: str | None = None,\n        client=None,  # this is the AsyncAzureOpenAI\n        litellm_params: dict = {},\n    ):\n        response = None\n        try:","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/completion/handler.py#L167-L203","documentation":"This is the catch-all handler at the end of Azure text completion: any exception that is not itself AzureOpenAIError is converted into AzureOpenAIError, preserving the original status_code/headers attributes if present (defaulting to 500). The message is str(e) of the underlying error — typically an openai.APIStatusError from the Azure OpenAI service.","triggerScenarios":"The Azure OpenAI service returned 4xx/5xx (401 bad key, 404 unknown deployment, 429 quota, 500s) and the OpenAI SDK raised; network timeouts (httpx.ConnectTimeout/ReadTimeout); JSON decode errors on truncated responses.","commonSituations":"Wrong api_key or expired key (401); deployment name in the model string does not exist in the resource (404); hitting token-per-minute rate limits (429); regional outages; short client timeouts on long completions.","solutions":["Inspect the wrapped error's status_code and message — they mirror the upstream Azure/OpenAI error and its headers (retry-after for 429s).","401/403: verify AZURE_API_KEY and the deployment's access settings; 404: verify the deployment name after 'azure/'.","429: honor retry-after, reduce RPM/TPM, or enable LiteLLM router retries/cooldowns.","Timeouts: pass a larger timeout= to the call and check network egress to <resource>.openai.azure.com."],"exampleFix":"# before\nresp = litellm.text_completion(model=\"azure/dep\", prompt=txt, timeout=5)  # ReadTimeout -> 500 wrap\n\n# after\nresp = litellm.text_completion(model=\"azure/dep\", prompt=txt, timeout=120, max_retries=3)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import AzureOpenAIError\n\ntry:\n    resp = litellm.text_completion(model=\"azure/dep\", prompt=txt)\nexcept AzureOpenAIError as e:\n    if e.status_code == 429:\n        wait = int(e.headers.get(\"retry-after\", \"5\")) if e.headers else 5\n        time.sleep(wait)\n        resp = litellm.text_completion(model=\"azure/dep\", prompt=txt)\n    elif e.status_code in (401, 403):\n        raise AuthError(str(e)) from e\n    elif e.status_code == 404:\n        raise ConfigError(\"Deployment not found — check model name\") from e\n    else:\n        raise","preventionTips":["Branch on e.status_code rather than parsing the message.","Use LiteLLM Router with num_retries and cooldown_time for 429/5xx resilience.","Set explicit timeout= and max_retries= per call instead of defaults."],"tags":["azure","upstream-error","error-mapping","http"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}