From 3948513a4c7f5b9a940ccac33c449c0757af97a4 Mon Sep 17 00:00:00 2001 From: Chesars Date: Wed, 11 Mar 2026 15:12:53 -0300 Subject: [PATCH] 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. --- litellm/llms/vertex_ai/common_utils.py | 19 ---------- litellm/llms/vertex_ai/vertex_llm_base.py | 5 +++ .../vertex_ai/test_vertex_ai_common_utils.py | 28 -------------- .../test_vertex_ai_qwen_global_endpoint.py | 37 +------------------ 4 files changed, 7 insertions(+), 82 deletions(-) diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.py index 3c5cbb65437..4a5bb558076 100644 --- a/litellm/llms/vertex_ai/common_utils.py +++ b/litellm/llms/vertex_ai/common_utils.py @@ -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]: diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index 21d36bd7fa1..dcf2c9ba8c7 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -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" 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 730ae26fbbe..d483a81a349 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 @@ -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", 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 a7ba23950d9..53e42a519bf 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 @@ -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."""