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]

fix: refuse to guess a vertex project when live passthrough has no model hint

mateo-berrid434787a20e5
diff --git a/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py b/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py
index e7887e33ca6..28067c842cd 100644
--- a/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py
+++ b/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py
@@ -126,6 +126,9 @@ class PassthroughEndpointRouter:
``deployment_key_to_vertex_credentials`` is only reachable when the caller names a project and location,
which WebSocket clients never do, so DB-stored deployments need this lookup to be usable at all.
+
+ With no model to go on, only deployments that agree on a project and location answer: guessing between
+ two Vertex projects would mint a token for one and later send the other one's model name
"""
llm_router: Final = self.llm_router_getter()
if llm_router is None:
@@ -135,16 +138,22 @@ class PassthroughEndpointRouter:
for deployment in (llm_router.get_model_list() or ())
if (credentials := self._resolve_vertex_deployment_credentials(deployment["litellm_params"])) is not None
)
- if len(resolved) == 0:
- return None
- return next(
+ matched: Final = next(
(
credentials
for deployment, credentials in resolved
if model is not None and self._deployment_matches_model(deployment, model)
),
- resolved[0][1],
+ None,
+ )
+ if matched is not None:
+ return matched
+ targets: Final = frozenset(
+ (credentials.vertex_project, credentials.vertex_location) for _, credentials in resolved
)
+ if len(targets) != 1:
+ return None
+ return resolved[0][1]
def _resolve_vertex_deployment_credentials(
self, litellm_params: LiteLLMParamsTypedDict
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_endpoint_router.py b/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_endpoint_router.py
index 7816178471f..f86bfb8bb1b 100644
--- a/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_endpoint_router.py
+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_endpoint_router.py
@@ -268,14 +268,29 @@ def test_vertex_model_hint_prefers_matching_deployment():
assert by_upstream_id is not None and by_upstream_id.vertex_project == "proj-live"
-def test_vertex_unmatched_hint_falls_back_to_first_flagged_deployment():
+def test_vertex_without_usable_hint_refuses_to_guess_between_projects():
passthrough_router = _passthrough_router(_two_vertex_deployments_router())
- unmatched = passthrough_router.get_vertex_credentials_from_router_deployments(model="unknown-model")
- no_hint = passthrough_router.get_vertex_credentials_from_router_deployments(model=None)
+ assert passthrough_router.get_vertex_credentials_from_router_deployments(model="unknown-model") is None
+ assert passthrough_router.get_vertex_credentials_from_router_deployments(model=None) is None
+
+
+def test_vertex_without_hint_falls_back_when_deployments_share_a_target():
+ llm_router = litellm.Router(
+ model_list=[
+ _vertex_deployment(
+ "gemini-flash", "vertex_ai/gemini-2.5-flash", vertex_project="proj-one", vertex_location="global"
+ ),
+ _vertex_deployment(
+ "gemini-live", "vertex_ai/gemini-live-2.5-flash", vertex_project="proj-one", vertex_location="global"
+ ),
+ ]
+ )
+ passthrough_router = _passthrough_router(llm_router)
+
+ resolved = passthrough_router.get_vertex_credentials_from_router_deployments(model=None)
- assert unmatched is not None and unmatched.vertex_project == "proj-first"
- assert no_hint is not None and no_hint.vertex_project == "proj-first"
+ assert resolved is not None and resolved.vertex_project == "proj-one"
def test_no_flagged_vertex_deployment_returns_none():