From 672284e491944e1a6df81e8c09d17d2d085806b0 Mon Sep 17 00:00:00 2001 From: PRABHU KIRAN VANDRANKI <72809214+VANDRANKI@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:17:30 -0400 Subject: [PATCH] fix(prometheus): read litellm_metadata fallback for budget metrics Fixes #29937 add_litellm_data_to_request stores all per-request metadata in litellm_params["litellm_metadata"] (not ["metadata"]) for these routes: - /v1/messages (Anthropic pass-through) - batches - responses - files - threads / assistants The Prometheus callback's _increment_remaining_budget_metrics was reading only litellm_params.get("metadata"), so user_api_key_team_max_budget was always None on those routes, causing _safe_get_remaining_budget to return float('inf') and the litellm_remaining_team_budget_metric (and key/user equivalents) to show +Inf even when a budget was set. Fix: fall back to litellm_params.get("litellm_metadata") when "metadata" does not contain the budget fields. --- litellm/integrations/prometheus.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 30af0dcb8ed..bf2478f5104 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -1362,7 +1362,13 @@ class PrometheusLogger(CustomLogger): user_id: Optional[str] = None, user_api_key_org_id: Optional[str] = None, ): - _metadata = litellm_params.get("metadata") or {} + # For batch/files/responses/thread/assistant endpoints, add_litellm_data_to_request + # stores budget metadata under "litellm_metadata" not "metadata" (fixes #29937). + _metadata = ( + litellm_params.get("metadata") + or litellm_params.get("litellm_metadata") + or {} + ) _team_spend = _metadata.get("user_api_key_team_spend", None) _team_max_budget = _metadata.get("user_api_key_team_max_budget", None)