feat(prometheus): add requested_model label to spend and requests metrics - #31410
Conversation
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — two-line label addition backed by a targeted regression test and no changes to request handling logic. The change is entirely additive: two new entries in two label-name lists, with the value already flowing through the existing enum_values.requested_model field. The call site (_increment_top_level_request_and_spend_metrics) and the label resolution helper (prometheus_label_factory) are untouched. Adding a Prometheus label is backward-compatible for all existing queries. The new test exercises the full set of related metrics and would fail on revert. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/types/integrations/prometheus.py | Adds REQUESTED_MODEL label to litellm_requests_metric and litellm_spend_metric label lists; minimal, correct, and consistent with sibling token metrics. |
| tests/test_litellm/integrations/test_prometheus_labels.py | Adds a pure unit regression test covering all five affected metrics; no network calls, no mock weakening. |
Reviews (1): Last reviewed commit: "feat(prometheus): add requested_model la..." | Re-trigger Greptile
Greptile SummaryAdds the
Confidence Score: 5/5Safe to merge — the change is two one-line label additions in a type-definition file with no runtime logic changes. Both changed files are tight and well-contained: the type definition and the counter initialization both read from the same No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/types/integrations/prometheus.py | Adds UserAPIKeyLabelNames.REQUESTED_MODEL to litellm_requests_metric and litellm_spend_metric label lists, making them consistent with the existing token metrics. |
| tests/test_litellm/integrations/test_prometheus_labels.py | Adds regression test test_requested_model_in_spend_and_requests_metrics that asserts requested_model is present in all five relevant metric label lists; mock-only, no network calls. |
Reviews (2): Last reviewed commit: "feat(prometheus): add requested_model la..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…rics litellm_spend_metric_total and litellm_requests_metric_total previously exposed only the resolved backend model_id and friendly model name, so operators could not group spend or request counts by the model alias the caller actually asked for when a router fronts multiple deployments behind one name. This adds the existing UserAPIKeyLabelNames.REQUESTED_MODEL to both labelname lists; the value is already populated upstream from standard_logging_payload["model_group"] and flows through the shared _increment_top_level_request_and_spend_metrics call site. The sibling token metrics (input/output/total) already carry the label, so this also restores cross-metric consistency. Resolves LIT-3796
2799d06 to
422b611
Compare
Relevant issues
Linear ticket
Resolves LIT-3796
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
Local proxy with two deployments behind one alias, real OpenAI traffic:
Before this PR (note: no
requested_modellabel):After this PR (note:
requested_model="aliased-fast-model"now appears on every row, all other labels unchanged):Adding a label is backward compatible for Prometheus and for any existing
sum()orsum by (existing_label)queries; only queries that explicitly enumerate the full label set change shapeType
🐛 Bug Fix
Changes
litellm_spend_metricandlitellm_requests_metricboth gainedUserAPIKeyLabelNames.REQUESTED_MODELin their labelnames list (litellm/types/integrations/prometheus.py). The value is already populated onUserAPIKeyLabelValues.requested_modelupstream fromstandard_logging_payload["model_group"], and the shared_increment_top_level_request_and_spend_metricscall site reads it through the existing helper, so no plumbing changes are needed. The sibling token metrics (litellm_input_tokens_metric,litellm_output_tokens_metric,litellm_total_tokens_metric) already carried the label; this makes the counter set consistentRegression test
test_requested_model_in_spend_and_requests_metricsintests/test_litellm/integrations/test_prometheus_labels.pyasserts the label is present on every metric in that family; reverting either source line makes the test fail with the exact missing-label assertion. One enterprise unit test (test_increment_top_level_request_and_spend_metrics) hard-coded the full kwargs oflabels(...)and required the newrequested_model=Noneentry to keep itsassert_called_once_withaligned