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
perf: avoid unconditional router lookups in success handler
Ephrim Stanley477c54184bda
diff --git a/litellm/proxy/hooks/parallel_request_limiter.py b/litellm/proxy/hooks/parallel_request_limiter.pyindex b0046fd035b..49c6436c22f 100644--- a/litellm/proxy/hooks/parallel_request_limiter.py+++ b/litellm/proxy/hooks/parallel_request_limiter.py@@ -14,8 +14,6 @@ from litellm.integrations.custom_logger import CustomLoggerfrom litellm.litellm_core_utils.core_helpers import _get_parent_otel_span_from_kwargsfrom litellm.proxy._types import CommonProxyErrors, CurrentItemRateLimit, UserAPIKeyAuthfrom litellm.proxy.auth.auth_utils import (- _get_deployment_default_rpm_limit,- _get_deployment_default_tpm_limit,get_key_model_rpm_limit,get_key_model_tpm_limit,)@@ -548,8 +546,14 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger):"model_rpm_limit" in user_api_key_metadataor "model_tpm_limit" in user_api_key_metadataor user_api_key_model_max_budget is not None- or _get_deployment_default_tpm_limit(model_group) is not None- or _get_deployment_default_rpm_limit(model_group) is not None+ or get_key_model_tpm_limit(+ user_api_key_dict, model_name=model_group+ )+ is not None+ or get_key_model_rpm_limit(+ user_api_key_dict, model_name=model_group+ )+ is not None)):request_count_api_key = (diff --git a/tests/test_litellm/proxy/auth/test_auth_utils.py b/tests/test_litellm/proxy/auth/test_auth_utils.pyindex d64f17e70ff..2058f61cb0f 100644--- a/tests/test_litellm/proxy/auth/test_auth_utils.py+++ b/tests/test_litellm/proxy/auth/test_auth_utils.py@@ -2,6 +2,7 @@Unit tests for auth_utils functions related to rate limiting and customer ID extraction."""+from typing import Optionalfrom unittest.mock import MagicMock, patchfrom litellm.proxy._types import UserAPIKeyAuth@@ -317,7 +318,7 @@ def test_get_end_user_id_falls_back_to_deprecated_user_header_name():assert result == "user-legacy"-def _make_deployment_dict(model_name: str, tpm: int = None, rpm: int = None) -> dict:+def _make_deployment_dict(model_name: str, tpm: Optional[int] = None, rpm: Optional[int] = None) -> dict:"""Helper to build a minimal deployment dict as returned by router.get_model_list."""litellm_params: dict = {"model": model_name}if tpm is not None:diff --git a/tests/test_litellm/proxy/test_model_info_default_limits.py b/tests/test_litellm/proxy/test_model_info_default_limits.pyindex 907f2390a89..8b85531785a 100644--- a/tests/test_litellm/proxy/test_model_info_default_limits.py+++ b/tests/test_litellm/proxy/test_model_info_default_limits.py@@ -3,6 +3,7 @@ Tests verifying that default_api_key_tpm_limit and default_api_key_rpm_limit setlitellm_params are returned by the /model/info endpoint."""+from typing import Optionalfrom unittest.mock import MagicMock, patchimport pytest@@ -13,8 +14,8 @@ from litellm.types.router import Deployment, LiteLLM_Params, ModelInfodef _make_deployment(model_name: str,- default_tpm: int = None,- default_rpm: int = None,+ default_tpm: Optional[int] = None,+ default_rpm: Optional[int] = None,) -> Deployment:params: dict = {"model": f"openai/{model_name}"}if default_tpm is not None: