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
_should_run_auth_on_metrics_endpoint
Ishaan Jaff96ce5dbf7ddf
diff --git a/litellm/proxy/middleware/prometheus_auth_middleware.py b/litellm/proxy/middleware/prometheus_auth_middleware.pyindex ae2481384b6..ca38a9d4452 100644--- a/litellm/proxy/middleware/prometheus_auth_middleware.py+++ b/litellm/proxy/middleware/prometheus_auth_middleware.py@@ -5,6 +5,7 @@ from fastapi import Requestfrom starlette.middleware.base import BaseHTTPMiddlewareimport litellm+from litellm.proxy._types import SpecialHeadersfrom litellm.proxy.auth.user_api_key_auth import user_api_key_auth@@ -13,12 +14,17 @@ class PrometheusAuthMiddleware(BaseHTTPMiddleware):# Check if this is a request to the metrics endpointif self._is_prometheus_metrics_endpoint(request):- try:- await user_api_key_auth(- request=request, api_key=request.headers.get("Authorization") or ""- )- except Exception as e:- raise e+ if self._should_run_auth_on_metrics_endpoint() is True:+ try:+ await user_api_key_auth(+ request=request,+ api_key=request.headers.get(+ SpecialHeaders.openai_authorization.value+ )+ or "",+ )+ except Exception as e:+ raise e# Process the request and get the responseresponse = await call_next(request)@@ -36,4 +42,14 @@ class PrometheusAuthMiddleware(BaseHTTPMiddleware):@staticmethoddef _should_run_auth_on_metrics_endpoint():+ """+ Returns True if auth should be run on the metrics endpoint++ False by default, set to True in proxy_config.yaml to enable++ ```yaml+ litellm_settings:+ require_auth_for_metrics_endpoint: true+ ```+ """return litellm.require_auth_for_metrics_endpointdiff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex 788bf9642d5..61950f55fe3 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -10,6 +10,5 @@ model_list:api_key: fake-keylitellm_settings:- require_auth_for_metrics_endpoint: truecallbacks: ["prometheus"]service_callback: ["prometheus_system"]\ No newline at end of file