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 req changes
Harshit28j99210e986792
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 839687b7d3e..5160d82dbc4 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -2162,22 +2162,24 @@ async def _run_background_health_check():"Error in shared health check, falling back to direct health check: %s",str(e),)- healthy_endpoints, unhealthy_endpoints = (- await _run_direct_health_check_with_instrumentation(- _llm_model_list,- health_check_details,- health_check_concurrency,- instrumentation_context,- )- )- else:- healthy_endpoints, unhealthy_endpoints = (- await _run_direct_health_check_with_instrumentation(+ (+ healthy_endpoints,+ unhealthy_endpoints,+ ) = await _run_direct_health_check_with_instrumentation(_llm_model_list,health_check_details,health_check_concurrency,instrumentation_context,)+ else:+ (+ healthy_endpoints,+ unhealthy_endpoints,+ ) = await _run_direct_health_check_with_instrumentation(+ _llm_model_list,+ health_check_details,+ health_check_concurrency,+ instrumentation_context,)# Update the global variable with the health check results@@ -7125,13 +7127,6 @@ async def audio_speech("audio/wav" # Gemini TTS returns WAV format after conversion)- # Proxy-level success hook (e.g. Prometheus litellm_proxy_total_requests_metric)- await proxy_logging_obj.post_call_success_hook(- data=data,- response=response, # type: ignore[arg-type]- user_api_key_dict=user_api_key_dict,- )-return StreamingResponse(_audio_speech_chunk_generator(response), # type: ignore[arg-type]media_type=media_type,diff --git a/tests/test_litellm/proxy/test_audio_speech_prometheus_hooks.py b/tests/test_litellm/proxy/test_audio_speech_prometheus_hooks.pyindex 00ca386a6ac..5a13a4dc531 100644--- a/tests/test_litellm/proxy/test_audio_speech_prometheus_hooks.py+++ b/tests/test_litellm/proxy/test_audio_speech_prometheus_hooks.py@@ -1,8 +1,3 @@-"""-Regression tests: proxy /v1/audio/speech (TTS) must call proxy-level success/failure-hooks so Prometheus metrics (litellm_proxy_total_requests_metric, litellm_proxy_failed_requests_metric)-and other callbacks see TTS requests.-"""import asyncioimport osfrom unittest.mock import AsyncMock, MagicMock, patch@@ -10,7 +5,6 @@ from unittest.mock import AsyncMock, MagicMock, patchimport pytestfrom fastapi.testclient import TestClient-# Import after path setup so proxy_server is loadablefrom litellm.proxy.auth.user_api_key_auth import user_api_key_authfrom litellm.proxy.proxy_server import app, initialize@@ -21,7 +15,7 @@ def _mock_user_api_key_auth():def _make_mock_tts_response():- """Mock response for handler: llm_call = await route_request(), response = await llm_call, then _audio_speech_chunk_generator does await response.aiter_bytes() and async for chunk in it."""+ """Mock response that simulates HttpxBinaryResponseContent with aiter_bytes."""async def _chunks():yield b"\xff\xfb"@@ -55,8 +49,15 @@ def client_no_auth():@pytest.mark.asyncio@pytest.mark.retry(retries=0)-async def test_audio_speech_success_calls_post_call_success_hook(client_no_auth):- """TTS success path must call proxy_logging_obj.post_call_success_hook (Prometheus total requests)."""+async def test_audio_speech_success_does_not_call_post_call_success_hook(+ client_no_auth,+):+ """TTS success path must NOT call post_call_success_hook.++ TTS returns a streaming binary response (HttpxBinaryResponseContent) which+ is not in LLMResponseTypes. Prometheus metrics for successful requests are+ tracked at the litellm level via async_log_success_event, not here.+ """mock_success_hook = AsyncMock()mock_failure_hook = AsyncMock()mock_pre_call = AsyncMock(side_effect=lambda *, data, **kw: data)@@ -91,11 +92,8 @@ async def test_audio_speech_success_calls_post_call_success_hook(client_no_auth)app.dependency_overrides = original_overridesassert response.status_code == 200- mock_success_hook.assert_awaited_once()+ mock_success_hook.assert_not_called()mock_failure_hook.assert_not_called()- # Ensure we passed through the right call type- call_kw = mock_success_hook.call_args.kwargs- assert "data" in call_kw and "user_api_key_dict" in call_kw@pytest.mark.asyncio