From 97092ab4c01de166b2a403357ab7b2cc37c6913c Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Wed, 15 Apr 2026 05:04:45 +0300 Subject: [PATCH] feat(prometheus): add api_provider label to spend metric (#25693) * feat(prometheus): add api_provider label to spend metric Add `api_provider` to `litellm_spend_metric` labels so users can build Grafana dashboards that break down spend by cloud provider (e.g. bedrock, anthropic, openai, azure, vertex_ai). The `api_provider` label already exists in UserAPIKeyLabelValues and is populated from `standard_logging_payload["custom_llm_provider"]`, but was not included in the spend metric's label list. * add api_provider to requests metric + add test Address review feedback: - Add api_provider to litellm_requests_metric too (same call-site as spend metric, keeps label sets in sync) - Add test_api_provider_in_spend_and_requests_metrics following the existing pattern in test_prometheus_labels.py --- litellm/types/integrations/prometheus.py | 2 ++ .../integrations/test_prometheus_labels.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/litellm/types/integrations/prometheus.py b/litellm/types/integrations/prometheus.py index 51a41f97e03..b1535208ec3 100644 --- a/litellm/types/integrations/prometheus.py +++ b/litellm/types/integrations/prometheus.py @@ -396,6 +396,7 @@ class PrometheusMetricLabels: UserAPIKeyLabelNames.CLIENT_IP.value, UserAPIKeyLabelNames.USER_AGENT.value, UserAPIKeyLabelNames.MODEL_ID.value, + UserAPIKeyLabelNames.API_PROVIDER.value, ] litellm_spend_metric = [ @@ -410,6 +411,7 @@ class PrometheusMetricLabels: UserAPIKeyLabelNames.CLIENT_IP.value, UserAPIKeyLabelNames.USER_AGENT.value, UserAPIKeyLabelNames.MODEL_ID.value, + UserAPIKeyLabelNames.API_PROVIDER.value, ] litellm_input_tokens_metric = [ diff --git a/tests/test_litellm/integrations/test_prometheus_labels.py b/tests/test_litellm/integrations/test_prometheus_labels.py index 2553eb06271..69127e15b8c 100644 --- a/tests/test_litellm/integrations/test_prometheus_labels.py +++ b/tests/test_litellm/integrations/test_prometheus_labels.py @@ -69,6 +69,21 @@ def test_model_id_in_required_metrics(): print(f"✅ {metric_name} contains model_id label") +def test_api_provider_in_spend_and_requests_metrics(): + """ + Test that api_provider label is present in spend and requests metrics + so users can build spend-by-provider and request-count-by-provider dashboards. + """ + api_provider_label = UserAPIKeyLabelNames.API_PROVIDER.value + + for metric_name in ["litellm_spend_metric", "litellm_requests_metric"]: + labels = PrometheusMetricLabels.get_labels(metric_name) + assert ( + api_provider_label in labels + ), f"Metric {metric_name} should contain api_provider label" + print(f"✅ {metric_name} contains api_provider label") + + def test_user_email_label_exists(): """Test that the USER_EMAIL label is properly defined""" assert UserAPIKeyLabelNames.USER_EMAIL.value == "user_email"