From c723d63e591a6c4a1fed1b9a276cdc52c874a100 Mon Sep 17 00:00:00 2001 From: Chesars Date: Mon, 19 Jan 2026 16:41:52 -0300 Subject: [PATCH] fix(vertex_ai): auto-resolve vertex_location from supported_regions - Add call to get_vertex_region() in partner models to auto-detect region - Improve get_vertex_region() to read supported_regions from model_cost - User-specified vertex_location still takes priority --- .../vertex_ai/vertex_ai_partner_models/main.py | 5 +++++ litellm/llms/vertex_ai/vertex_llm_base.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py index 123d925f7c1..67fc6adc127 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/main.py @@ -161,6 +161,11 @@ class VertexAIPartnerModels(VertexBase): else: raise ValueError(f"Unknown partner model: {model}") + # Resolve vertex_location based on model's supported_regions + vertex_location = self.get_vertex_region( + vertex_region=vertex_location, model=model + ) + api_base = self.get_complete_vertex_url( custom_api_base=api_base, vertex_location=vertex_location, diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index 86e14a30df4..9f569c525bd 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -49,8 +49,20 @@ class VertexBase: self.async_handler: Optional[AsyncHTTPHandler] = None def get_vertex_region(self, vertex_region: Optional[str], model: str) -> str: - if is_global_only_vertex_model(model): - return "global" + import litellm + + # Try to get supported_regions directly from model_cost + # Check both with and without vertex_ai/ prefix + model_key = f"vertex_ai/{model}" if not model.startswith("vertex_ai/") else model + model_info = litellm.model_cost.get(model_key, {}) + supported_regions = model_info.get("supported_regions") + + if supported_regions and len(supported_regions) > 0: + # If user didn't specify region, use the first supported region + if vertex_region is None: + return supported_regions[0] + # If user specified a region, trust them + return vertex_region return vertex_region or "us-central1" def load_auth(