fix: Reduce count route gate complexity and fix the vLLM auth docstring

Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
This commit is contained in:
Alberto Perdomo 2026-10-28 16:31:03 +00:00
parent 9a98716851
commit 5c775dc63c
No known key found for this signature in database
2 changed files with 10 additions and 7 deletions

View file

@ -52,7 +52,7 @@ def _input_tokens(payload: Mapping[str, JsonValue]) -> int:
def _auth_header(api_key: object) -> Mapping[str, str]:
"""vLLM commonly runs keyless, so an unset key sends no auth header at all."""
"""Send no auth header when the key is unset, since vLLM commonly runs keyless."""
return {"Authorization": f"Bearer {api_key}"} if isinstance(api_key, str) and api_key else {}

View file

@ -14711,13 +14711,18 @@ async def _raise_if_count_route_model_unserved(
model: str,
requested: str,
team_id: str | None,
require_deployment: bool,
) -> None:
"""Raise 404 not_found_error when routing cannot pick a deployment for ``model``.
A model a sibling replica loaded but this replica has not is read through before the
rejection, the way route_request recovers from the same miss.
"""
if _count_route_model_is_served(llm_router, model, team_id):
if (
not require_deployment
or llm_router.router_general_settings.pass_through_all_models
or _count_route_model_is_served(llm_router, model, team_id)
):
return
from litellm.proxy.common_utils.registry_read_through import model_registry_read_through
@ -15369,12 +15374,10 @@ async def count_request_tokens(
if llm_router is not None:
# An unserved model on the Anthropic count route is a 404, not a local estimate from an
# unrelated tokenizer. pass_through_all_models opts out, as on the completion routes.
pass_through_all_models: Final = llm_router.router_general_settings.pass_through_all_models
request_kwargs: Final = dict(_count_route_request_kwargs(user_api_key_dict))
if require_deployment and not pass_through_all_models:
await _raise_if_count_route_model_unserved(
llm_router, resolution_model, request.model, _count_route_team_id(user_api_key_dict)
)
await _raise_if_count_route_model_unserved(
llm_router, resolution_model, request.model, _count_route_team_id(user_api_key_dict), require_deployment
)
# get 1 deployment corresponding to the model
try:
deployment = await llm_router.async_get_available_deployment(