Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions litellm/types/integrations/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class PrometheusMetricLabels:
UserAPIKeyLabelNames.USER_EMAIL.value,
UserAPIKeyLabelNames.CLIENT_IP.value,
UserAPIKeyLabelNames.USER_AGENT.value,
UserAPIKeyLabelNames.REQUESTED_MODEL.value,
UserAPIKeyLabelNames.MODEL_ID.value,
UserAPIKeyLabelNames.API_PROVIDER.value,
]
Expand All @@ -424,6 +425,7 @@ class PrometheusMetricLabels:
UserAPIKeyLabelNames.USER_EMAIL.value,
UserAPIKeyLabelNames.CLIENT_IP.value,
UserAPIKeyLabelNames.USER_AGENT.value,
UserAPIKeyLabelNames.REQUESTED_MODEL.value,
UserAPIKeyLabelNames.MODEL_ID.value,
UserAPIKeyLabelNames.API_PROVIDER.value,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ def test_increment_top_level_request_and_spend_metrics(prometheus_logger):
api_provider="openai",
client_ip=None,
user_agent=None,
requested_model=None,
)
prometheus_logger.litellm_requests_metric.labels().inc.assert_called_once()

Expand All @@ -626,6 +627,7 @@ def test_increment_top_level_request_and_spend_metrics(prometheus_logger):
api_provider="openai",
client_ip=None,
user_agent=None,
requested_model=None,
)
prometheus_logger.litellm_spend_metric.labels().inc.assert_called_once_with(0.1)

Expand Down
28 changes: 28 additions & 0 deletions tests/test_litellm/integrations/test_prometheus_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ def test_model_id_in_required_metrics():
print(f"✅ {metric_name} contains model_id label")


def test_requested_model_in_spend_and_requests_metrics():
"""
Regression test for LIT-3796.

litellm_spend_metric and litellm_requests_metric must expose the
requested_model label so spend and request counts can be grouped by the
model alias the caller asked for, not just the backend deployment that
served the request. The sibling token metrics (input/output/total)
already carry this label; spend and requests were the odd ones out, even
though both are emitted side-by-side from the same call site.
"""
requested_model_label = UserAPIKeyLabelNames.REQUESTED_MODEL.value

metrics_with_requested_model = [
"litellm_spend_metric",
"litellm_requests_metric",
"litellm_input_tokens_metric",
"litellm_output_tokens_metric",
"litellm_total_tokens_metric",
]

for metric_name in metrics_with_requested_model:
labels = PrometheusMetricLabels.get_labels(metric_name)
assert requested_model_label in labels, (
f"Metric {metric_name} should contain requested_model label"
)


def test_route_normalization_for_responses_api():
"""
Test that route normalization prevents high cardinality in Prometheus metrics
Expand Down
Loading