Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

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

mateo-berri32293295f8fe
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-..."