fix(vertex-ai): warn on region override and remove dead is_global_only_vertex_model

Add verbose_logger.warning when user-specified region is overridden by
supported_regions. Remove now-unused is_global_only_vertex_model function
and its tests since get_vertex_region handles all region logic directly.
This commit is contained in:
Chesars 2026-03-11 15:12:53 -03:00
parent f3ceb69e9f
commit 3948513a4c
4 changed files with 7 additions and 82 deletions

View file

@ -940,25 +940,6 @@ def construct_target_url(
return updated_url
def is_global_only_vertex_model(model: str) -> bool:
"""
Check if a model is only available in the global region.
Args:
model: The model name to check
Returns:
True if the model is only available in global region, False otherwise
"""
from litellm.utils import get_supported_regions
supported_regions = get_supported_regions(
model=model, custom_llm_provider="vertex_ai"
)
if supported_regions is None:
return False
return "global" in supported_regions
class VertexAIModelInfo(BaseLLMModelInfo):
def get_token_counter(self) -> Optional[BaseTokenCounter]:

View file

@ -62,6 +62,11 @@ class VertexBase:
return supported_regions[0]
# If user specified a region not supported by this model, override it
if vertex_region not in supported_regions:
verbose_logger.warning(
"Vertex AI model '%s' does not support region '%s' "
"(supported: %s). Routing to '%s'.",
model, vertex_region, supported_regions, supported_regions[0],
)
return supported_regions[0]
return vertex_region
return vertex_region or "us-central1"

View file

@ -558,34 +558,6 @@ def test_get_vertex_url_global_region(stream, expected_endpoint_suffix):
assert url == expected_url
@pytest.mark.parametrize(
"supported_regions, expected_result",
[
(None, False), # get_supported_regions returns None
([], False), # empty list, no global region
(["us-central1"], False), # only regional, no global
(["global"], True), # only global region
(["global", "us-central1"], True), # global and other regions
(
["us-central1", "global", "europe-west1"],
True,
), # global among multiple regions
],
)
def test_is_global_only_vertex_model(supported_regions, expected_result):
"""Test is_global_only_vertex_model with various supported regions scenarios"""
from litellm.llms.vertex_ai.common_utils import is_global_only_vertex_model
with patch("litellm.utils.get_supported_regions") as mock_get_supported_regions:
mock_get_supported_regions.return_value = supported_regions
result = is_global_only_vertex_model("test-model")
assert result == expected_result
mock_get_supported_regions.assert_called_once_with(
model="test-model", custom_llm_provider="vertex_ai"
)
@pytest.mark.parametrize(
"model_cost_entry, vertex_region, expected_region",

View file

@ -2,8 +2,8 @@
Tests for Vertex AI Qwen MaaS models that require the global endpoint.
These tests verify that:
1. Qwen models are correctly identified as global-only models
2. The correct global URL is constructed (https://aiplatform.googleapis.com)
1. The correct global URL is constructed (https://aiplatform.googleapis.com)
2. The get_vertex_region method resolves regions from model_cost supported_regions
3. The completion() and responses() API work with Qwen models
"""
@ -19,7 +19,6 @@ sys.path.insert(
) # Adds the parent directory to the system path
import litellm
from litellm.llms.vertex_ai.common_utils import is_global_only_vertex_model
from litellm.llms.vertex_ai.vertex_llm_base import VertexBase
from litellm.types.llms.vertex_ai import VertexPartnerProvider
@ -48,38 +47,6 @@ def clean_vertex_env():
os.environ[var] = value
class TestQwenGlobalOnlyDetection:
"""Test that Qwen models are correctly identified as global-only."""
@pytest.mark.parametrize(
"model",
[
"vertex_ai/qwen/qwen3-next-80b-a3b-instruct-maas",
"vertex_ai/qwen/qwen3-next-80b-a3b-thinking-maas",
"vertex_ai/qwen/qwen3-235b-a22b-instruct-2507-maas",
"vertex_ai/qwen/qwen3-coder-480b-a35b-instruct-maas",
],
)
def test_qwen_models_are_global_only(self, model):
"""Test that Qwen MaaS models are identified as global-only."""
# This test requires the model_cost to have supported_regions: ["global"]
# If the model is not in model_cost, it should return False (fallback behavior)
result = is_global_only_vertex_model(model)
# Note: This will return True only if the model is in model_cost with supported_regions: ["global"]
# If running without the updated model_cost, this may return False
assert isinstance(result, bool)
def test_non_global_model_returns_false(self):
"""Test that non-global models return False."""
result = is_global_only_vertex_model("vertex_ai/gemini-1.5-pro")
assert result is False
def test_unknown_model_returns_false(self):
"""Test that unknown models return False (fallback behavior)."""
result = is_global_only_vertex_model("vertex_ai/unknown-model-xyz")
assert result is False
class TestVertexBaseGetVertexRegion:
"""Test the get_vertex_region method using model_cost lookup."""