From 32293295f8fe9811a18179b556e12cdb6c4a11bc Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 3 Sep 2026 15:40:35 -0700 Subject: [PATCH] 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. --- litellm/proxy/auth/auth_utils.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py index fd746d62e76..12e6f75889e 100644 --- a/litellm/proxy/auth/auth_utils.py +++ b/litellm/proxy/auth/auth_utils.py @@ -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-..."