refactor(proxy): move UNMATCHED_REQUEST_ROUTE to constants

Centralize the Prometheus unmatched-route sentinel in constants.py
so metrics paths share one canonical value.
This commit is contained in:
Souravrajvi0 2026-08-10 17:37:34 +00:00
parent 53acca8a4b
commit f53f6d2259
4 changed files with 7 additions and 11 deletions

View file

@ -1334,6 +1334,8 @@ LITELLM_TRUNCATION_DB_SAFEGUARD_NOTE: Final = (
########################### LiteLLM Proxy Specific Constants ###########################
########################################################################################
UNMATCHED_REQUEST_ROUTE: Final = "/unmatched"
# Standard headers that are always checked for customer/end-user ID (no configuration required)
# These headers work out-of-the-box for tools like Claude Code that support custom headers
STANDARD_CUSTOMER_ID_HEADERS: Final = [

View file

@ -11,7 +11,7 @@ from fastapi import HTTPException, Request, status
import litellm
from litellm import Router, provider_list
from litellm._logging import verbose_proxy_logger
from litellm.constants import MINIMUM_CUSTOM_KEY_LENGTH, STANDARD_CUSTOMER_ID_HEADERS
from litellm.constants import MINIMUM_CUSTOM_KEY_LENGTH, STANDARD_CUSTOMER_ID_HEADERS, UNMATCHED_REQUEST_ROUTE
from litellm.litellm_core_utils.safe_json_loads import safe_json_loads
from litellm.litellm_core_utils.url_utils import (
SSRFError,
@ -767,8 +767,6 @@ def normalize_request_route(route: str) -> str:
return route
UNMATCHED_REQUEST_ROUTE: Final = "/unmatched"
# Literal proxy routes safe to emit when FastAPI's route template is unavailable
# (e.g. auth failure on an unmatched scope). Dynamic segments must never appear
# here — those are covered by get_request_route_template() or normalize_request_route().

View file

@ -451,10 +451,8 @@ def test_route_normalization_preserves_static_routes():
def test_unmatched_scanner_routes_collapse_for_metrics():
"""Unknown paths must not create unbounded Prometheus route labels."""
from litellm.proxy.auth.auth_utils import (
UNMATCHED_REQUEST_ROUTE,
resolve_request_route_for_metrics,
)
from litellm.constants import UNMATCHED_REQUEST_ROUTE
from litellm.proxy.auth.auth_utils import resolve_request_route_for_metrics
scanner_paths = [
"/files/pRzAdaV1.php",

View file

@ -2951,10 +2951,8 @@ class TestResolveRequestRouteForMetrics:
assert resolve_request_route_for_metrics(None, route) == route
def test_collapses_unknown_paths_to_unmatched(self):
from litellm.proxy.auth.auth_utils import (
UNMATCHED_REQUEST_ROUTE,
resolve_request_route_for_metrics,
)
from litellm.constants import UNMATCHED_REQUEST_ROUTE
from litellm.proxy.auth.auth_utils import resolve_request_route_for_metrics
scanner_paths = [
"/files/pRzAdaV1.php",