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.
This commit is contained in:
PRABHU KIRAN VANDRANKI 2026-06-09 12:17:30 -04:00
parent a72414a061
commit 672284e491

View file

@ -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)