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
track litellm_request_latency_metric
Ishaan Jaff06a362d35fb2
diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.pyindex 1471f59b75c..dadafa80e35 100644--- a/litellm/integrations/prometheus.py+++ b/litellm/integrations/prometheus.py@@ -60,6 +60,25 @@ class PrometheusLogger(CustomLogger):],)+ # request latency metrics+ self.litellm_request_latency_metric = Histogram(+ "litellm_request_latency_metric",+ "Total latency (seconds) for a request to LiteLLM",+ labelnames=[+ "model",+ "litellm_call_id",+ ],+ )++ self.litellm_deployment_latency_metric = Histogram(+ "litellm_deployment_latency_metric",+ "Total latency (seconds) for a models LLM API call",+ labelnames=[+ "model",+ "litellm_call_id",+ ],+ )+# Counter for spendself.litellm_spend_metric = Counter("litellm_spend_metric",@@ -329,6 +348,25 @@ class PrometheusLogger(CustomLogger):user_api_key, user_api_key_alias, model_group).set(remaining_tokens)+ # latency metrics+ total_time: timedelta = kwargs.get("end_time") - kwargs.get("start_time")+ total_time_seconds = total_time.total_seconds()+ api_call_total_time: timedelta = kwargs.get("end_time") - kwargs.get(+ "api_call_start_time"+ )++ api_call_total_time_seconds = api_call_total_time.total_seconds()++ litellm_call_id = kwargs.get("litellm_call_id")++ self.litellm_request_latency_metric.labels(model, litellm_call_id).observe(+ total_time_seconds+ )++ self.litellm_deployment_latency_metric.labels(model, litellm_call_id).observe(+ api_call_total_time_seconds+ )+# set x-ratelimit headersif premium_user is True:self.set_llm_deployment_success_metrics(diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex 65c7f70525c..7c524eb18a0 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -4,7 +4,9 @@ model_list:model: openai/fakeapi_key: fake-keyapi_base: https://exampleopenaiendpoint-production.up.railway.app/-+litellm_settings:+ success_callback: ["prometheus"]+ failure_callback: ["prometheus"]guardrails:- guardrail_name: "lakera-pre-guard"litellm_params: