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
Revert "[Feature]: Replace HTTPException with ParallelRequestLimitError in pa…" (#15095)
Ishaan Jaff73bfef1a1f90
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 462f89c29e4..078c4348206 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -1301,7 +1301,6 @@ from .exceptions import (ImageFetchError,NotFoundError,RateLimitError,- ParallelRequestLimitError,ServiceUnavailableError,OpenAIError,ContextWindowExceededError,diff --git a/litellm/exceptions.py b/litellm/exceptions.pyindex b4230ecdf65..77fb9c1faef 100644--- a/litellm/exceptions.py+++ b/litellm/exceptions.py@@ -353,49 +353,6 @@ class RateLimitError(openai.RateLimitError): # type: ignorereturn _message-class ParallelRequestLimitError(RateLimitError): # type: ignore- def __init__(- self,- message: str,- llm_provider: Optional[str] = "litellm",- model: Optional[str] = "unknown",- headers: Optional[dict] = None,- response: Optional[httpx.Response] = None,- litellm_debug_info: Optional[str] = None,- max_retries: Optional[int] = None,- num_retries: Optional[int] = None,- ):- # Store headers for later access (similar to FastAPI HTTPException)- self.headers = headers or {}-- # Create a response with custom headers if provided- if response is None:- response_headers = headers- response = httpx.Response(- status_code=429,- headers=response_headers,- request=httpx.Request(- method="POST",- url="https://litellm.ai/parallel-request-limiter",- ),- )-- # Initialize parent with appropriate defaults for parallel request limiting- super().__init__(- message=message,- llm_provider=llm_provider or "litellm",- model=model or "unknown",- response=response,- litellm_debug_info=litellm_debug_info,- max_retries=max_retries,- num_retries=num_retries,- )-- # Update the message prefix to be more specific- self.message = "litellm.ParallelRequestLimitError: {}".format(message)- self.detail = message # Store original detail for FastAPI compatibility--# sub class of rate limit error - meant to give more granularity for error handling context window exceeded errorsclass ContextWindowExceededError(BadRequestError): # type: ignoredef __init__(@@ -791,7 +748,6 @@ LITELLM_EXCEPTION_TYPES = [Timeout,PermissionDeniedError,RateLimitError,- ParallelRequestLimitError,ContextWindowExceededError,RejectedRequestError,ContentPolicyViolationError,diff --git a/litellm/proxy/hooks/parallel_request_limiter_v3.py b/litellm/proxy/hooks/parallel_request_limiter_v3.pyindex 76a588f745d..0a49d7f6759 100644--- a/litellm/proxy/hooks/parallel_request_limiter_v3.py+++ b/litellm/proxy/hooks/parallel_request_limiter_v3.py@@ -22,7 +22,6 @@ from typing import (from litellm import DualCachefrom litellm._logging import verbose_proxy_logger-from litellm.exceptions import ParallelRequestLimitErrorfrom litellm.integrations.custom_logger import CustomLoggerfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.types.llms.openai import BaseLiteLLMOpenAIResponseObject@@ -701,8 +700,9 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):f"Limit resets at: {reset_time_formatted}")- raise ParallelRequestLimitError(- message=detail,+ raise HTTPException(+ status_code=429,+ detail=detail,headers={"retry-after": str(self.window_size),"rate_limit_type": str(status["rate_limit_type"]),diff --git a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.pyindex d25e2638537..511eb5bbb89 100644--- a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py+++ b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py@@ -14,7 +14,6 @@ from fastapi import HTTPExceptionimport litellmfrom litellm import Routerfrom litellm.caching.caching import DualCache-from litellm.exceptions import ParallelRequestLimitErrorfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.proxy.hooks.parallel_request_limiter_v3 import (_PROXY_MaxParallelRequestsHandler_v3 as _PROXY_MaxParallelRequestsHandler,@@ -93,7 +92,7 @@ async def test_sliding_window_rate_limit_v3(monkeypatch):)# Fourth request should fail (counter would be 4, limit is 3, so 4 > 3)- with pytest.raises(ParallelRequestLimitError) as exc_info:+ with pytest.raises(HTTPException) as exc_info:await parallel_request_handler.async_pre_call_hook(user_api_key_dict=user_api_key_dict,cache=local_cache,@@ -375,7 +374,7 @@ async def test_normal_router_call_tpm_v3(monkeypatch, rate_limit_object):await local_cache.async_increment_cache(key=counter_key, value=15, ttl=2) # Use up most of our 10 token limit# Make another request to test rate limiting - this should fail as we've consumed tokens- with pytest.raises(ParallelRequestLimitError) as exc_info:+ with pytest.raises(HTTPException) as exc_info:await parallel_request_handler.async_pre_call_hook(user_api_key_dict=user_api_key_dict,cache=local_cache,@@ -778,7 +777,7 @@ async def test_tpm_api_key_rate_limits_v3():async def mock_should_rate_limit(descriptors, **kwargs):nonlocal captured_descriptorscaptured_descriptors = descriptors- # Return Error response to ensure ParallelRequestLimitError+ # Return Error response to ensure HTTPExceptionreturn {"overall_code": "OVER_LIMIT","statuses": [{'code': 'OK', 'current_limit': 2, 'limit_remaining': 1, 'rate_limit_type': 'requests', 'descriptor_key': 'model_per_key'},@@ -796,7 +795,7 @@ async def test_tpm_api_key_rate_limits_v3():data={"model": model},call_type="",)- except ParallelRequestLimitError as e:+ except HTTPException as e:error=eassert e.status_code == 429assert "rate_limit_type" in e.headers@@ -854,7 +853,7 @@ async def test_rpm_api_key_rate_limits_v3():async def mock_should_rate_limit(descriptors, **kwargs):nonlocal captured_descriptorscaptured_descriptors = descriptors- # Return Error response to ensure ParallelRequestLimitError+ # Return Error response to ensure HTTPExceptionreturn {"overall_code": "OVER_LIMIT","statuses": [{'code': 'OVER_LIMIT', 'current_limit': 2, 'limit_remaining': -2, 'rate_limit_type': 'requests', 'descriptor_key': 'model_per_key'},@@ -872,7 +871,7 @@ async def test_rpm_api_key_rate_limits_v3():data={"model": model},call_type="",)- except ParallelRequestLimitError as e:+ except HTTPException as e:error=eassert e.status_code == 429assert "rate_limit_type" in e.headers@@ -923,7 +922,7 @@ async def test_team_member_rate_limits_v3():async def mock_should_rate_limit(descriptors, **kwargs):nonlocal captured_descriptorscaptured_descriptors = descriptors- # Return OK response to avoid ParallelRequestLimitError+ # Return OK response to avoid HTTPExceptionreturn {"overall_code": "OK","statuses": []