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: address Greptile review comments
Sameer Kankutec12717f494a5
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.pyindex 84f9730a370..b86a7595ae9 100644--- a/litellm/proxy/common_request_processing.py+++ b/litellm/proxy/common_request_processing.py@@ -912,6 +912,11 @@ class ProxyBaseLLMRequestProcessing:if skip_pre_call_logic:logging_obj = self.data.get("litellm_logging_obj")+ if logging_obj is None:+ raise ValueError(+ "skip_pre_call_logic=True requires litellm_logging_obj to be set in data. "+ "Ensure common_processing_pre_call_logic was called before using this parameter."+ )else:self.data, logging_obj = await self.common_processing_pre_call_logic(request=request,diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.pyindex 055fdeb84f4..8023853e263 100644--- a/litellm/proxy/response_api_endpoints/endpoints.py+++ b/litellm/proxy/response_api_endpoints/endpoints.py@@ -136,6 +136,7 @@ async def responses_api(user_request_timeout=user_request_timeout,user_max_tokens=user_max_tokens,user_api_base=user_api_base,+ model=None,route_type="aresponses",llm_router=llm_router,)diff --git a/tests/proxy_unit_tests/test_response_polling_pre_call_checks.py b/tests/proxy_unit_tests/test_response_polling_pre_call_checks.pyindex b39f1bf43d2..cdea075d0d8 100644--- a/tests/proxy_unit_tests/test_response_polling_pre_call_checks.py+++ b/tests/proxy_unit_tests/test_response_polling_pre_call_checks.py@@ -11,10 +11,11 @@ import sysfrom unittest.mock import AsyncMock, MagicMock, patchimport pytest-from fastapi import Request, Response+from fastapi import HTTPException, Request, Responsesys.path.insert(0, os.path.abspath("../.."))+import litellmfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing@@ -102,3 +103,63 @@ class TestSkipPreCallLogic:mock_pre_call.assert_called_once()+class TestPollingEndpointPreCallGuard:+ """Test that the polling endpoint enforces pre-call checks before polling ID creation"""++ @pytest.mark.asyncio+ async def test_rate_limit_error_prevents_polling_id_creation(self):+ """When pre-call checks raise, generate_polling_id must not be called"""+ from litellm.proxy.response_polling.polling_handler import ResponsePollingHandler++ rate_limit_exc = litellm.RateLimitError(+ message="TPM limit exceeded",+ llm_provider="",+ model="gpt-4",+ )++ generate_polling_id_mock = MagicMock(return_value="litellm_poll_test")++ with (+ patch.object(+ ProxyBaseLLMRequestProcessing,+ "common_processing_pre_call_logic",+ new_callable=AsyncMock,+ side_effect=rate_limit_exc,+ ),+ patch.object(+ ProxyBaseLLMRequestProcessing,+ "_handle_llm_api_exception",+ new_callable=AsyncMock,+ return_value=HTTPException(status_code=429, detail="Rate limit exceeded"),+ ),+ patch.object(ResponsePollingHandler, "generate_polling_id", generate_polling_id_mock),+ ):+ # Simulate the endpoint logic directly (avoids proxy_server import complexity)+ data = {"model": "gpt-4", "background": True}+ processor = ProxyBaseLLMRequestProcessing(data=data)++ raised_exc = None+ try:+ await processor.common_processing_pre_call_logic(+ request=MagicMock(spec=Request),+ general_settings={},+ proxy_logging_obj=AsyncMock(),+ user_api_key_dict=MagicMock(spec=UserAPIKeyAuth),+ version="1.0.0",+ proxy_config=MagicMock(),+ user_model=None,+ user_temperature=None,+ user_request_timeout=None,+ user_max_tokens=None,+ user_api_base=None,+ model=None,+ route_type="aresponses",+ llm_router=MagicMock(),+ )+ except litellm.RateLimitError as e:+ raised_exc = e++ # The exception was raised before generate_polling_id could be called+ assert raised_exc is not None+ generate_polling_id_mock.assert_not_called()+