The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(logging): keep proxy-side rate limits as expected client errors
mateo-berria6e1708e6c24
diff --git a/litellm/litellm_core_utils/core_helpers.py b/litellm/litellm_core_utils/core_helpers.pyindex 1089499a64f..9d5b0c86da6 100644--- a/litellm/litellm_core_utils/core_helpers.py+++ b/litellm/litellm_core_utils/core_helpers.py@@ -58,7 +58,17 @@ def safe_divide(return numerator / denominator+def _is_proxy_rejection(exception: BaseException) -> bool:+ try:+ from starlette.exceptions import HTTPException+ except ImportError:+ return False+ return isinstance(exception, HTTPException)++def _is_provider_originated(exception: BaseException) -> bool:+ if _is_proxy_rejection(exception):+ return Falseif getattr(exception, "llm_provider", None):return Truefrom litellm.llms.base_llm.chat.transformation import BaseLLMException@@ -74,6 +84,8 @@ def is_expected_client_error(exception: BaseException | None) -> bool:client error and keeps its traceback: a mapped litellm exception carries``llm_provider``, and the raw ``BaseLLMException`` that provider handlersraise before mapping (the /v1/messages route surfaces it as-is) is one too.+ The proxy's own limiters raise ``HTTPException`` subclasses that also carry+ an ``llm_provider``, so any ``HTTPException`` stays a proxy rejection.ProxyException stores the status on .code (as a str), HTTPException andlitellm exceptions on .status_code.diff --git a/tests/test_litellm/litellm_core_utils/test_core_helpers.py b/tests/test_litellm/litellm_core_utils/test_core_helpers.pyindex efbf7192a0e..a1f3f5eac70 100644--- a/tests/test_litellm/litellm_core_utils/test_core_helpers.py+++ b/tests/test_litellm/litellm_core_utils/test_core_helpers.py@@ -286,6 +286,7 @@ class TestIsExpectedClientError:from litellm.exceptions import AuthenticationError, RateLimitErrorfrom litellm.litellm_core_utils.core_helpers import is_expected_client_errorfrom litellm.llms.anthropic.common_utils import AnthropicError+ from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitErrorprovider_auth_failure = AuthenticationError(message="AnthropicException - API key is invalid.", llm_provider="anthropic", model="claude-haiku-4-5"@@ -298,6 +299,12 @@ class TestIsExpectedClientError:unmapped_provider_failure = AnthropicError(status_code=401, message='{"type":"authentication_error"}')assert is_expected_client_error(unmapped_provider_failure) is False+ proxy_rate_limit = ProxyRateLimitError(+ detail={"error": "Max parallel requests reached"}, model="claude-haiku-4-5", llm_provider="anthropic"+ )+ assert proxy_rate_limit.llm_provider == "anthropic"+ assert is_expected_client_error(proxy_rate_limit) is True+class RouterRejection(Exception):def __init__(self):self.status_code = 429