allow requiring auth for /metrics endpoint

This commit is contained in:
Ishaan Jaff 2025-04-04 17:35:02 -07:00
parent 8d76da03fe
commit 253060cb09
5 changed files with 87 additions and 24 deletions

View file

@ -224,18 +224,9 @@ def initialize_callbacks_on_proxy( # noqa: PLR0915
litellm.callbacks = imported_list # type: ignore
if "prometheus" in value:
if premium_user is not True:
verbose_proxy_logger.warning(
f"Prometheus metrics are only available for premium users. {CommonProxyErrors.not_premium_user.value}"
)
from litellm.proxy.proxy_server import app
from litellm.integrations.prometheus import PrometheusLogger
verbose_proxy_logger.debug("Starting Prometheus Metrics on /metrics")
from prometheus_client import make_asgi_app
# Add prometheus asgi middleware to route /metrics requests
metrics_app = make_asgi_app()
app.mount("/metrics", metrics_app)
PrometheusLogger._mount_metrics_endpoint(premium_user)
else:
litellm.callbacks = [
get_instance_fn(