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(prometheus): skip customer budget cache read when end_user tracking is off
yassin81d57cbad7ff
diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.pyindex bb38b25ab99..7ef5ce1d39b 100644--- a/litellm/integrations/prometheus.py+++ b/litellm/integrations/prometheus.py@@ -4204,7 +4204,7 @@ class PrometheusLogger(CustomLogger):end_user_id: str | None,response_cost: float,):- if self._customer_budget_gauges_are_noop():+ if self._customer_budget_gauges_are_noop() or not _customer_budget_metrics_enabled():returnif not end_user_id:diff --git a/tests/test_litellm/integrations/test_prometheus_user_team_metrics.py b/tests/test_litellm/integrations/test_prometheus_user_team_metrics.pyindex 7969c4741ef..0fc91748af2 100644--- a/tests/test_litellm/integrations/test_prometheus_user_team_metrics.py+++ b/tests/test_litellm/integrations/test_prometheus_user_team_metrics.py@@ -1150,6 +1150,29 @@ async def test_set_customer_budget_metrics_after_api_request_without_end_user_isassert prometheus_logger.litellm_remaining_customer_budget_metric._metrics == {}+async def test_set_customer_budget_metrics_after_api_request_skips_cache_when_end_user_tracking_off(+ prometheus_logger, monkeypatch+):+ import sys++ import litellm++ monkeypatch.setattr(litellm, "enable_end_user_cost_tracking_prometheus_only", False)+ monkeypatch.setattr(litellm, "disable_end_user_cost_tracking", False)+ mock_proxy_server = MagicMock()+ mock_proxy_server.user_api_key_cache.async_get_cache = AsyncMock()++ with patch.dict(sys.modules, {"litellm.proxy.proxy_server": mock_proxy_server}):+ await prometheus_logger._set_customer_budget_metrics_after_api_request(+ end_user_id="cust-off",+ response_cost=1.0,+ )++ mock_proxy_server.user_api_key_cache.async_get_cache.assert_not_awaited()+ assert prometheus_logger.litellm_remaining_customer_budget_metric._metrics == {}++@pytest.mark.asyncioasync def test_initialize_customer_budget_metrics_emits_gauges_for_budgeted_customers(prometheus_logger, customer_metrics_enabled