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] CI failures: mypy type error, ruff lint, and flaky router test
yuneng-jiang03231f3b266c
diff --git a/litellm/integrations/focus/destinations/vantage_destination.py b/litellm/integrations/focus/destinations/vantage_destination.pyindex 9e6028900f9..4b9d270d2fa 100644--- a/litellm/integrations/focus/destinations/vantage_destination.py+++ b/litellm/integrations/focus/destinations/vantage_destination.py@@ -6,7 +6,7 @@ import csvimport iofrom typing import Any, Optional-import httpx+import httpx # noqa: F401 - used at runtime (AsyncClient, HTTPStatusError)from litellm._logging import verbose_loggerdiff --git a/litellm/proxy/response_polling/background_streaming.py b/litellm/proxy/response_polling/background_streaming.pyindex 682ad4943b9..5ec0aac8e29 100644--- a/litellm/proxy/response_polling/background_streaming.py+++ b/litellm/proxy/response_polling/background_streaming.py@@ -9,7 +9,7 @@ https://platform.openai.com/docs/api-reference/responses-streaming"""import asyncioimport json-from typing import Any+from typing import Any, Optional, castfrom fastapi import Request, Response@@ -17,6 +17,7 @@ from litellm._logging import verbose_proxy_loggerfrom litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuthfrom litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessingfrom litellm.proxy.response_polling.polling_handler import ResponsePollingHandler+from litellm.types.llms.openai import ResponsesAPIStatusasync def background_streaming_task( # noqa: PLR0915@@ -114,7 +115,7 @@ async def background_streaming_task( # noqa: PLR0915UPDATE_INTERVAL = 0.150 # 150ms batching interval# Track the terminal event from the stream (may not be "completed")- terminal_status = None # Will be set by response.completed/failed/incomplete/cancelled+ terminal_status: Optional[ResponsesAPIStatus] = None # Will be set by response.completed/failed/incomplete/cancelledterminal_error = None_event_to_status = {"response.completed": "completed",@@ -249,9 +250,12 @@ async def background_streaming_task( # noqa: PLR0915# Terminal event - extract all ResponsesAPIResponse fields# https://platform.openai.com/docs/api-reference/responses-streamingresponse_data = event.get("response", {})- terminal_status = response_data.get(- "status",- _event_to_status.get(event_type, "completed"),+ terminal_status = cast(+ ResponsesAPIStatus,+ response_data.get(+ "status",+ _event_to_status.get(event_type, "completed"),+ ),)# Extract error for failed responsesdiff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex 8c37214e19e..b563a2e3c57 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -643,7 +643,13 @@ def test_arouter_responses_api_bridge():## CONFIRM MODEL NAME IS STRIPPEDclient = HTTPHandler()- with patch.object(client, "post", return_value=MagicMock()) as mock_post:+ mock_response = MagicMock()+ mock_response.status_code = 200+ mock_response.headers = {"content-type": "application/json"}+ mock_response.json.return_value = {"id": "resp_test", "object": "response", "status": "completed", "output": []}+ mock_response.text = '{"id": "resp_test", "object": "response", "status": "completed", "output": []}'++ with patch.object(client, "post", return_value=mock_response) as mock_post:try:result = router.completion(model="[IP-approved] o3-pro",