refactor(proxy): resolve the Bedrock route model through an early return

The Bedrock branch of get_model_from_request reassigned the already resolved
model binding. Move the route parsing into a helper that returns the URL model
or None so the caller picks between it and the body model without rebinding.
This commit is contained in:
mateo-berri 2026-09-03 15:40:35 -07:00
parent 6981ccf0ca
commit 32293295f8

View file

@ -1982,23 +1982,26 @@ def get_model_from_request(
model = vertex_match.group(1)
if route.lower().startswith("/bedrock"):
bedrock_endpoint = re.sub(r"^/bedrock/", "", route, flags=re.IGNORECASE)
is_bedrock_count_tokens_route = (
"count_tokens" in bedrock_endpoint.lower() or "count-tokens" in bedrock_endpoint.lower()
)
if not is_bedrock_count_tokens_route:
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
_extract_model_from_bedrock_endpoint,
)
try:
model = _extract_model_from_bedrock_endpoint(bedrock_endpoint)
except ValueError:
pass
bedrock_model: Final = _model_from_bedrock_route(route)
return model if bedrock_model is None else bedrock_model
return model
def _model_from_bedrock_route(route: str) -> str | None:
bedrock_endpoint: Final = re.sub(r"^/bedrock/", "", route, flags=re.IGNORECASE)
if "count_tokens" in bedrock_endpoint.lower() or "count-tokens" in bedrock_endpoint.lower():
return None
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
_extract_model_from_bedrock_endpoint,
)
try:
return _extract_model_from_bedrock_endpoint(bedrock_endpoint)
except ValueError:
return None
def abbreviate_api_key(api_key: str) -> str:
if len(api_key) < MINIMUM_CUSTOM_KEY_LENGTH:
return "sk-..."