Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/route_priority.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:01 +0000

1"""Starlette matches routes in registration order, so the routes that take the most traffic go first.""" 

2 

3from collections.abc import Sequence 

4from typing import Final 

5 

6from starlette.routing import BaseRoute, Route 

7 

8HOT_ROUTE_PATHS: Final[frozenset[str]] = frozenset( 

9 ( 

10 "/health/liveliness", 

11 "/health/liveness", 

12 "/v1/chat/completions", 

13 "/chat/completions", 

14 "/v1/messages", 

15 ) 

16) 

17 

18 

19def _is_hot(route: BaseRoute) -> bool: 

20 return isinstance(route, Route) and route.path in HOT_ROUTE_PATHS 

21 

22 

23def hot_routes_first(routes: Sequence[BaseRoute]) -> list[BaseRoute]: # mutable-ok: assigned to Router.routes, a list 

24 return sorted(routes, key=lambda route: not _is_hot(route))