BerriAI/litellm · error · AzureOpenAIError
{str(e)}
Error message
{str(e)} What it means
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.
Source
Thrown at litellm/llms/azure/completion/handler.py:185
additional_args={
"headers": headers,
"api_version": api_version,
"api_base": api_base,
},
)
return openai_text_completion_config.convert_to_chat_model_response_object(
response_object=TextCompletionResponse(**stringified_response),
model_response_object=model_response,
)
except AzureOpenAIError as e:
raise e
except Exception as e:
status_code: Final = getattr(e, "status_code", 500)
error_headers = getattr(e, "headers", None)
error_response: Final = getattr(e, "response", None)
if error_headers is None and error_response:
error_headers = getattr(error_response, "headers", None)
raise AzureOpenAIError(status_code=status_code, message=str(e), headers=error_headers)
async def acompletion(
self,
api_key: str | None,
api_version: str,
model: str,
api_base: str,
data: dict,
timeout: Any,
model_response: ModelResponse,
logging_obj: Any,
max_retries: int,
azure_ad_token: str | None = None,
client=None, # this is the AsyncAzureOpenAI
litellm_params: dict = {},
):
response = None
try:View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
# before resp = litellm.text_completion(model="azure/dep", prompt=txt, timeout=5) # ReadTimeout -> 500 wrap # after resp = litellm.text_completion(model="azure/dep", prompt=txt, timeout=120, max_retries=3)
Defensive patterns
Strategy: try-catch
Try / catch
from litellm.exceptions import AzureOpenAIError
try:
resp = litellm.text_completion(model="azure/dep", prompt=txt)
except AzureOpenAIError as e:
if e.status_code == 429:
wait = int(e.headers.get("retry-after", "5")) if e.headers else 5
time.sleep(wait)
resp = litellm.text_completion(model="azure/dep", prompt=txt)
elif e.status_code in (401, 403):
raise AuthError(str(e)) from e
elif e.status_code == 404:
raise ConfigError("Deployment not found — check model name") from e
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- raw_response.text
- Azure Document Intelligence analysis failed: {error_msg}
- Azure Document Intelligence analysis failed with status: {op
- error_msg (upstream response error message)
- raw_response.text
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/5b1881a054d8ac13.
Report an issue: GitHub.