fix(vertex-ai): override unsupported user region for models with supported_regions

- get_vertex_region now overrides user-specified region when it's not in
  the model's supported_regions list (prevents 404 for users with a
  global VERTEXAI_LOCATION default hitting global-only models)
- Add supported_regions: ["global"] to glm-5-maas in both JSON files
- Update tests to cover the override behavior
This commit is contained in:
Chesars 2026-03-11 14:55:51 -03:00
parent 689cbaa6c1
commit f3ceb69e9f
5 changed files with 16 additions and 8 deletions

View file

@ -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"

View file

@ -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,

View file

@ -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,

View file

@ -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

View file

@ -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."""