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(vertex-ai): override unsupported user region for models with supported_regions

Chesarsf3ceb69e9f5c
diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py
index f958c76137b..21d36bd7fa1 100644
--- a/litellm/llms/vertex_ai/vertex_llm_base.py
+++ b/litellm/llms/vertex_ai/vertex_llm_base.py
@@ -60,7 +60,9 @@ class VertexBase:
# 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
+ # If user specified a region not supported by this model, override it
+ if vertex_region not in supported_regions:
+ return supported_regions[0]
return vertex_region
return vertex_region or "us-central1"
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index 01dca07e9dd..788e13b8fa9 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -33857,6 +33857,7 @@
"mode": "chat",
"output_cost_per_token": 3.2e-06,
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#glm-models",
+ "supported_regions": ["global"],
"supports_function_calling": true,
"supports_prompt_caching": true,
"supports_reasoning": true,
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index 01dca07e9dd..788e13b8fa9 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -33857,6 +33857,7 @@
"mode": "chat",
"output_cost_per_token": 3.2e-06,
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#glm-models",
+ "supported_regions": ["global"],
"supports_function_calling": true,
"supports_prompt_caching": true,
"supports_reasoning": true,
diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
index 4dfde61509a..730ae26fbbe 100644
--- a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
+++ b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
@@ -592,12 +592,16 @@ def test_is_global_only_vertex_model(supported_regions, expected_result):
[
# Model with supported_regions=["global"], no user region -> use "global"
({"supported_regions": ["global"]}, None, "global"),
- # Model with supported_regions=["global"], user specifies region -> trust user
- ({"supported_regions": ["global"]}, "us-central1", "us-central1"),
- # Model with supported_regions=["global"], user specifies region -> trust user
- ({"supported_regions": ["global"]}, "europe-west1", "europe-west1"),
+ # Model with supported_regions=["global"], user passes unsupported region -> override to "global"
+ ({"supported_regions": ["global"]}, "us-central1", "global"),
+ # Model with supported_regions=["global"], user passes unsupported region -> override to "global"
+ ({"supported_regions": ["global"]}, "europe-west1", "global"),
# Model with supported_regions=["us-west2"], no user region -> use "us-west2"
({"supported_regions": ["us-west2"]}, None, "us-west2"),
+ # Model with supported_regions=["us-west2", "us-central1"], user passes supported region -> respect it
+ ({"supported_regions": ["us-west2", "us-central1"]}, "us-central1", "us-central1"),
+ # Model with supported_regions=["us-west2", "us-central1"], user passes unsupported region -> override
+ ({"supported_regions": ["us-west2", "us-central1"]}, "europe-west1", "us-west2"),
# No model_cost entry, no user region -> default us-central1
({}, None, "us-central1"),
# No model_cost entry, user specifies region -> use specified region
diff --git a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py
index 46f3f1e7817..a7ba23950d9 100644
--- a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py
+++ b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py
@@ -98,8 +98,8 @@ class TestVertexBaseGetVertexRegion:
)
assert result == "global"
- def test_global_model_with_user_region_trusts_user(self):
- """Test that user-specified region is preserved even for global-only models."""
+ def test_global_model_with_unsupported_user_region_overrides(self):
+ """Test that unsupported user region is overridden for global-only models."""
vertex_base = VertexBase()
with patch.dict(
@@ -111,7 +111,7 @@ class TestVertexBaseGetVertexRegion:
vertex_region="us-central1",
model="qwen/qwen3-next-80b-a3b-instruct-maas",
)
- assert result == "us-central1"
+ assert result == "global"
def test_non_global_model_uses_provided_region(self):
"""Test that non-global models use the provided region."""