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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(prometheus.py): working e2e calls w/ userapikeymetadata
Krrish Dholakiaa1a0e99638eb
diff --git a/enterprise/litellm_enterprise/integrations/prometheus.py b/enterprise/litellm_enterprise/integrations/prometheus.pyindex b472ccbb357..3b37e14b896 100644--- a/enterprise/litellm_enterprise/integrations/prometheus.py+++ b/enterprise/litellm_enterprise/integrations/prometheus.py@@ -21,6 +21,7 @@ from litellm._logging import print_verbose, verbose_loggerfrom litellm.integrations.custom_logger import CustomLoggerfrom litellm.proxy._types import LiteLLM_TeamTable, UserAPIKeyAuthfrom litellm.types.integrations.prometheus import *+from litellm.types.integrations.prometheus import _sanitize_prometheus_label_namefrom litellm.types.utils import StandardLoggingPayloadfrom litellm.utils import get_end_user_id_for_cost_tracking@@ -2247,12 +2248,10 @@ def prometheus_label_factory(if enum_values.custom_metadata_labels is not None:for key, value in enum_values.custom_metadata_labels.items():- if key in supported_enum_labels:- filtered_labels[key] = value- else:- filtered_labels[key] = (- "None" # this happens for dynamically added metadata labels- )+ # check sanitized key+ sanitized_key = _sanitize_prometheus_label_name(key)+ if sanitized_key in supported_enum_labels:+ filtered_labels[sanitized_key] = value# Add custom tags if configuredif enum_values.tags is not None:diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 96d9ea0cc31..5d8052493a1 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -6,4 +6,4 @@ model_list:litellm_settings:callbacks: ["prometheus"]- custom_prometheus_metadata_labels: ["metadata.initiative"]\ No newline at end of file+ custom_prometheus_metadata_labels: ["metadata.initiative", "metadata.business-unit"]\ No newline at end of filediff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 73052d14957..44e26313f95 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -636,9 +636,11 @@ class LiteLLMProxyRequestSetup:+ LiteLLM_ManagementEndpoint_MetadataFields):added_metadata[k] = v- data[_metadata_variable_name].setdefault(- "user_api_key_auth_metadata", {}- ).update(added_metadata)+ if data[_metadata_variable_name].get("user_api_key_auth_metadata") is None:+ data[_metadata_variable_name]["user_api_key_auth_metadata"] = {}+ data[_metadata_variable_name]["user_api_key_auth_metadata"].update(+ added_metadata+ )return data@staticmethoddiff --git a/litellm/types/integrations/prometheus.py b/litellm/types/integrations/prometheus.pyindex 9c1a14a830e..a3dd4dcb1c6 100644--- a/litellm/types/integrations/prometheus.py+++ b/litellm/types/integrations/prometheus.py@@ -426,13 +426,13 @@ class PrometheusMetricLabels:# Buffer monitoring metrics - these typically don't need additional labelslitellm_pod_lock_manager_size: List[str] = []-+litellm_in_memory_daily_spend_update_queue_size: List[str] = []-+litellm_redis_daily_spend_update_queue_size: List[str] = []-+litellm_in_memory_spend_update_queue_size: List[str] = []-+litellm_redis_spend_update_queue_size: List[str] = []@staticmethod