litellm - ✅(Solved) Fix Add api_provider label to litellm_spend_metric for spend-by-provider dashboards [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25692Fetched 2026-04-16 06:37:08
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
1
Author
Participants
Timeline (top)
cross-referenced ×1labeled ×1

Root Cause

  • Using label_replace() in PromQL to extract the provider from the model label — doesn't work because LiteLLM strips the provider prefix.
  • Using deployment metrics (litellm_deployment_success_responses_total) which have api_provider — only gives request count, not spend.
  • Creating separate Grafana queries per known model name pattern — brittle and can't distinguish providers that share the same model name (e.g. OpenAI direct vs Azure OpenAI both show as gpt-5.1).

Fix Action

Fixed

PR fix notes

PR #25693: feat(prometheus): add api_provider label to spend metric

Description (problem / solution / changelog)

Summary

Closes https://github.com/BerriAI/litellm/issues/25692

  • Add UserAPIKeyLabelNames.API_PROVIDER to the litellm_spend_metric label list in PrometheusMetricLabels
  • This enables Grafana dashboards to break down spend by cloud provider (e.g. bedrock, anthropic, openai, azure, vertex_ai)
  • The api_provider value is already populated from standard_logging_payload["custom_llm_provider"] — this just adds it to the metric's label set

Motivation

The model label on litellm_spend_metric contains the raw model name with the provider prefix stripped (e.g. gpt-5.1 instead of openai/gpt-5.1, global.anthropic.claude-opus-4-6-v1 instead of bedrock/global.anthropic...). This makes it impossible to build spend-by-provider dashboards, and impossible to distinguish providers that share model names (e.g. OpenAI direct vs Azure OpenAI).

Test plan

  • Verify litellm_spend_metric_total includes api_provider label after the change
  • Verify existing dashboards using litellm_spend_metric are not broken (new label is additive)
  • Verify api_provider values match expected providers (e.g. bedrock, anthropic, openai, azure, vertex_ai)

Changed files

  • litellm/types/integrations/prometheus.py (modified, +2/-0)
  • tests/test_litellm/integrations/test_prometheus_labels.py (modified, +15/-0)
RAW_BUFFERClick to expand / collapse

Feature Request

Is your feature request related to a problem?

When building Grafana dashboards to visualize spend by cloud provider (e.g. Bedrock vs Anthropic direct vs Azure vs OpenAI), the litellm_spend_metric counter lacks the api_provider label, making it impossible to break down cost by provider.

The model label on the spend metric contains the raw model name (e.g. claude-opus-4-6, global.anthropic.claude-opus-4-6-v1, gpt-5.1) with the provider prefix stripped, so you can't reliably determine which provider served the request.

Describe the solution you'd like

Add UserAPIKeyLabelNames.API_PROVIDER to the litellm_spend_metric label list in PrometheusMetricLabels.

The api_provider value is already populated in UserAPIKeyLabelValues from standard_logging_payload["custom_llm_provider"] and already used by other metrics (deployment metrics, batch metrics). It just needs to be added to the spend metric's label list.

This is a one-line change in litellm/types/integrations/prometheus.py.

Describe alternatives you've considered

  • Using label_replace() in PromQL to extract the provider from the model label — doesn't work because LiteLLM strips the provider prefix.
  • Using deployment metrics (litellm_deployment_success_responses_total) which have api_provider — only gives request count, not spend.
  • Creating separate Grafana queries per known model name pattern — brittle and can't distinguish providers that share the same model name (e.g. OpenAI direct vs Azure OpenAI both show as gpt-5.1).

Additional context

The same label could also be useful on litellm_input_tokens_metric and litellm_output_tokens_metric for token-by-provider dashboards.

extent analysis

TL;DR

Add the api_provider label to the litellm_spend_metric by including UserAPIKeyLabelNames.API_PROVIDER in the label list in PrometheusMetricLabels.

Guidance

  • Review the litellm/types/integrations/prometheus.py file to locate the litellm_spend_metric label list.
  • Verify that UserAPIKeyLabelValues is correctly populated with the api_provider value from standard_logging_payload["custom_llm_provider"].
  • Consider adding the api_provider label to other relevant metrics, such as litellm_input_tokens_metric and litellm_output_tokens_metric, for more comprehensive dashboards.
  • Test the updated metric labels in Grafana to ensure correct spend breakdown by provider.

Example

No code example is provided as the change is described as a one-line modification in litellm/types/integrations/prometheus.py, but it would involve adding UserAPIKeyLabelNames.API_PROVIDER to the litellm_spend_metric label list.

Notes

This solution assumes that the api_provider value is correctly populated in UserAPIKeyLabelValues and that the label is not already included in the litellm_spend_metric label list.

Recommendation

Apply the workaround by adding the api_provider label to the litellm_spend_metric as it is a targeted and minimal change that addresses the specific issue of breaking down cost by provider in Grafana dashboards.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING