Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

added litellm_spend_metric

mubashir1osmani2626123aca31
diff --git a/enterprise/litellm_enterprise/integrations/prometheus.py b/enterprise/litellm_enterprise/integrations/prometheus.py
index 742f2dbbe9b..efee1a7783e 100644
--- a/enterprise/litellm_enterprise/integrations/prometheus.py
+++ b/enterprise/litellm_enterprise/integrations/prometheus.py
@@ -110,15 +110,7 @@ class PrometheusLogger(CustomLogger):
self.litellm_spend_metric = self._counter_factory(
"litellm_spend_metric",
"Total spend on LLM requests",
- labelnames=[
- "end_user",
- "hashed_api_key",
- "api_key_alias",
- "model",
- "team",
- "team_alias",
- "user",
- ],
+ labelnames=self.get_labels_for_metric("litellm_spend_metric"),
)
# Counter for total_output_tokens
@@ -321,6 +313,7 @@ class PrometheusLogger(CustomLogger):
documentation="deprecated - use litellm_proxy_total_requests_metric. Total number of LLM calls to litellm - track total per API Key, team, user",
labelnames=self.get_labels_for_metric("litellm_requests_metric"),
)
+
except Exception as e:
print_verbose(f"Got exception on init prometheus client {str(e)}")
raise e
diff --git a/litellm/types/integrations/prometheus.py b/litellm/types/integrations/prometheus.py
index 4ab0ccf5022..4637c05d144 100644
--- a/litellm/types/integrations/prometheus.py
+++ b/litellm/types/integrations/prometheus.py
@@ -163,6 +163,7 @@ DEFINED_PROMETHEUS_METRICS = Literal[
"litellm_proxy_failed_requests_metric",
"litellm_deployment_latency_per_output_token",
"litellm_requests_metric",
+ "litellm_spend_metric",
"litellm_total_tokens_metric",
"litellm_input_tokens_metric",
"litellm_output_tokens_metric",
@@ -290,6 +291,16 @@ class PrometheusMetricLabels:
UserAPIKeyLabelNames.USER_EMAIL.value,
]
+ litellm_spend_metric = [
+ UserAPIKeyLabelNames.END_USER.value,
+ UserAPIKeyLabelNames.API_KEY_HASH.value,
+ UserAPIKeyLabelNames.API_KEY_ALIAS.value,
+ UserAPIKeyLabelNames.v1_LITELLM_MODEL_NAME.value,
+ UserAPIKeyLabelNames.TEAM.value,
+ UserAPIKeyLabelNames.TEAM_ALIAS.value,
+ UserAPIKeyLabelNames.USER.value,
+ ]
+
litellm_input_tokens_metric = [
UserAPIKeyLabelNames.END_USER.value,
UserAPIKeyLabelNames.API_KEY_HASH.value,