mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
allow adding auth on /metrics endpoint
This commit is contained in:
parent
dea96e17bb
commit
5b6b1c0fb8
2 changed files with 6 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
Prometheus Auth Middleware
|
||||
"""
|
||||
from fastapi import Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
import litellm
|
||||
|
@ -24,7 +25,10 @@ class PrometheusAuthMiddleware(BaseHTTPMiddleware):
|
|||
or "",
|
||||
)
|
||||
except Exception as e:
|
||||
raise e
|
||||
return JSONResponse(
|
||||
status_code=401,
|
||||
content=f"Unauthorized access to metrics endpoint: {getattr(e, 'message', str(e))}",
|
||||
)
|
||||
|
||||
# Process the request and get the response
|
||||
response = await call_next(request)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue