{"record":{"id":"30b8989a2befe42f","repo":"BerriAI/litellm","slug":"exception-provider-apiconnectionerror-message-30b898","errorCode":null,"errorMessage":"{exception_provider} APIConnectionError - {message}\\n{_redact_string(traceback.format_exc())}","messagePattern":"(.+?) APIConnectionError - (.+?)\\\\n(.+?)","errorType":"exception","errorClass":"APIConnectionError","httpStatus":500,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":2061,"sourceCode":"            raise Timeout(\n                message=f\"AzureException Timeout - {message}\",\n                model=model,\n                litellm_debug_info=extra_information,\n                llm_provider=\"azure\",\n                exception_status_code=original_exception.status_code,\n            )\n        else:\n            raise APIError(\n                status_code=original_exception.status_code,\n                message=f\"AzureException APIError - {message}\",\n                llm_provider=\"azure\",\n                litellm_debug_info=extra_information,\n                model=model,\n                request=httpx.Request(method=\"POST\", url=\"https://openai.com/\"),\n            )\n    else:\n        # if no status code then it is an APIConnectionError: https://github.com/openai/openai-python#handling-errors\n        raise APIConnectionError(\n            message=f\"{exception_provider} APIConnectionError - {message}\\n{_redact_string(traceback.format_exc())}\",\n            llm_provider=\"azure\",\n            model=model,\n            litellm_debug_info=extra_information,\n            request=httpx.Request(method=\"POST\", url=\"https://openai.com/\"),\n        )\n\n\ndef _map_openrouter_exception(\n    *,\n    model: str,\n    original_exception: _ProviderHTTPException,\n    custom_llm_provider: str,\n    error_str: str,\n    exception_type: str,\n    exception_provider: str,\n    extra_information: str,\n) -> None:","sourceCodeStart":2043,"sourceCodeEnd":2079,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L2043-L2079","documentation":"When an Azure exception carries no status_code attribute, _map_azure_exception assumes the request never reached a valid HTTP response and raises litellm.APIConnectionError. The message embeds the exception_provider, the original message, and a redacted traceback, because for connection errors the SDK traceback is usually the only diagnostic (see the openai-python error-handling convention referenced in the code).","triggerScenarios":"Network-level failures before/while talking to Azure: DNS resolution failure, connection refused, TLS certificate errors, proxy misconfiguration, httpx.ConnectError/ReadError, or an api_base pointing at an unreachable host.","commonSituations":"Wrong or malformed azure_ad_token / api_base in env vars; corporate egress proxies blocking *.openai.azure.com; containers with no DNS; self-signed TLS interception; transient network drops in CI runners.","solutions":["Read the embedded traceback in the message — it names the underlying network error (DNS, TLS, proxy, refused).","Verify connectivity: curl your api_base endpoint (e.g. https://<resource>.openai.azure.com) from the same host/container.","Fix environment config: AZURE_API_BASE, AZURE_API_KEY / azure_ad_token, and any HTTPS_PROXY/HTTP_PROXY settings.","For transient drops, configure retries: litellm.completion(..., num_retries=3) which retries APIConnectionError."],"exampleFix":"# before\nlitellm.completion(model=\"azure/dep\", messages=msgs)\n\n# after\nimport litellm\ntry:\n    litellm.completion(model=\"azure/dep\", messages=msgs)\nexcept litellm.APIConnectionError as e:\n    # message contains original exception + redacted traceback\n    log.error(\"network failure talking to Azure: %s\", e)\n    raise","handlingStrategy":"retry","validationCode":"# pre-flight: can we reach the Azure endpoint at all?\nimport socket, ssl\nfrom urllib.parse import urlparse\nhost = urlparse(os.environ[\"AZURE_API_BASE\"]).hostname\ntry:\n    socket.create_connection((host, 443), timeout=5).close()\n    print(\"reachable\")\nexcept OSError as e:\n    print(\"network issue before calling litellm:\", e)","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(**kwargs)\nexcept litellm.APIConnectionError as e:\n    if \"Azure\" in str(e) or kwargs.get(\"model\", \"\").startswith(\"azure/\"):\n        log.warning(\"azure network failure (traceback in message): %s\", e)\n        resp = litellm.completion(num_retries=3, **kwargs)  # or fix DNS/proxy then retry\n    else:\n        raise","preventionTips":["Smoke-test AZURE_API_BASE reachability from every deploy environment at startup.","Keep HTTPS_PROXY/NO_PROXY correct in containers; missing proxy config is the top cause.","Set num_retries so transient connection errors are retried automatically.","Treat the embedded traceback as the diagnostic, not the exception class name."],"tags":["azure","connection-error","network","no-status-code","litellm","traceback"],"backgroundTag":"api-connection-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}