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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(vertex_ai): use aiplatform.{geo}.rep.googleapis.com for multi-region locations (#26281)
milan-berrib6d0f6b649bc
diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.pyindex fb8fd903409..ccd4d4f2934 100644--- a/litellm/llms/vertex_ai/common_utils.py+++ b/litellm/llms/vertex_ai/common_utils.py@@ -229,6 +229,10 @@ def get_vertex_base_url() -> str:"""Get the base URL for Vertex AI API calls.++ - ``global`` uses the global control plane host.+ - Multi-region geographies (e.g. ``us``, ``eu``) use ``aiplatform.{geo}.rep.googleapis.com``.+ - Regional locations (e.g. ``us-central1``) use ``{region}-aiplatform.googleapis.com``."""if vertex_location == "global":return "https://aiplatform.googleapis.com"@@ -236,6 +240,8 @@ def get_vertex_base_url(raise ValueError("vertex_location is required")if not re.match(r"^[a-z][a-z0-9-]*$", vertex_location):raise ValueError("Invalid vertex_location format")+ if "-" not in vertex_location:+ return f"https://aiplatform.{vertex_location}.rep.googleapis.com"return f"https://{vertex_location}-aiplatform.googleapis.com"diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.pyindex 8a86b98fee2..418715cb9cd 100644--- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py+++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py@@ -1497,7 +1497,9 @@ class VertexAIPassThroughHandler(BaseVertexAIPassThroughHandler):def get_vertex_base_url(vertex_location: Optional[str]) -> str:"""- Returns the base URL for Vertex AI based on the provided location.+ Base URL for Vertex AI pass-through (trailing slash for URL joining).++ Keep location rules aligned with ``litellm.llms.vertex_ai.common_utils.get_vertex_base_url``."""if vertex_location == "global":return "https://aiplatform.googleapis.com/"@@ -1505,6 +1507,8 @@ def get_vertex_base_url(vertex_location: Optional[str]) -> str:raise ValueError("vertex_location is required")if not re.match(r"^[a-z][a-z0-9-]*$", vertex_location):raise ValueError("Invalid vertex_location format")+ if "-" not in vertex_location:+ return f"https://aiplatform.{vertex_location}.rep.googleapis.com/"return f"https://{vertex_location}-aiplatform.googleapis.com/"@@ -1708,7 +1712,8 @@ async def _base_vertex_proxy_route(Base function for Vertex AI passthrough routes.Handles common logic for all Vertex AI services.- Default base_target_url is `https://{vertex_location}-aiplatform.googleapis.com/`+ Default base_target_url is derived from ``get_vertex_base_url`` in this module+ (regional, ``global``, or multi-region ``.rep.`` hosts), with a trailing slash.Args:endpoint: The endpoint path@@ -2280,11 +2285,7 @@ async def vertex_ai_live_websocket_passthrough(returnhost_location = resolved_location or vertex_llm_base.get_default_vertex_location()- host = (- "aiplatform.googleapis.com"- if host_location == "global"- else f"{host_location}-aiplatform.googleapis.com"- )+ host = get_vertex_base_url(host_location).removeprefix("https://").rstrip("/")service_url = (f"wss://{host}/ws/google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent")diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_global_url_support.py b/tests/test_litellm/llms/vertex_ai/test_vertex_global_url_support.pyindex 7b359af9b89..5a007f5a4f6 100644--- a/tests/test_litellm/llms/vertex_ai/test_vertex_global_url_support.py+++ b/tests/test_litellm/llms/vertex_ai/test_vertex_global_url_support.py@@ -5,6 +5,7 @@ This test suite ensures that all Vertex AI endpoints properly handle the 'globalwhich uses a different URL format than regional endpoints.Regional: https://{region}-aiplatform.googleapis.com/...+Multi-region: https://aiplatform.{geo}.rep.googleapis.com/...Global: https://aiplatform.googleapis.com/..."""@@ -30,6 +31,8 @@ class TestVertexBaseURL:("europe-west1", "https://europe-west1-aiplatform.googleapis.com"),("asia-northeast1", "https://asia-northeast1-aiplatform.googleapis.com"),("global", "https://aiplatform.googleapis.com"),+ ("us", "https://aiplatform.us.rep.googleapis.com"),+ ("eu", "https://aiplatform.eu.rep.googleapis.com"),],)def test_get_vertex_base_url(self, vertex_location, expected_base_url):diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.pyindex cafdff9997e..06748e3f477 100644--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py@@ -21,6 +21,7 @@ from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (bedrock_llm_proxy_route,create_pass_through_route,cursor_proxy_route,+ get_vertex_base_url,llm_passthrough_factory_proxy_route,milvus_proxy_route,openai_proxy_route,@@ -31,6 +32,35 @@ from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (from litellm.types.passthrough_endpoints.vertex_ai import VertexPassThroughCredentials+class TestVertexPassthroughGetVertexBaseUrl:+ """Module-local get_vertex_base_url (trailing slash); rules match common_utils."""++ @pytest.mark.parametrize(+ "vertex_location, expected",+ [+ ("global", "https://aiplatform.googleapis.com/"),+ ("us-central1", "https://us-central1-aiplatform.googleapis.com/"),+ ("us", "https://aiplatform.us.rep.googleapis.com/"),+ ("eu", "https://aiplatform.eu.rep.googleapis.com/"),+ ],+ )+ def test_returns_base_with_trailing_slash(self, vertex_location, expected):+ assert get_vertex_base_url(vertex_location) == expected++ @pytest.mark.parametrize(+ "vertex_location, expected_host",+ [+ ("global", "aiplatform.googleapis.com"),+ ("us-central1", "us-central1-aiplatform.googleapis.com"),+ ("us", "aiplatform.us.rep.googleapis.com"),+ ("eu", "aiplatform.eu.rep.googleapis.com"),+ ],+ )+ def test_websocket_host_strips_scheme(self, vertex_location, expected_host):+ host = get_vertex_base_url(vertex_location).removeprefix("https://").rstrip("/")+ assert host == expected_host++class TestBaseOpenAIPassThroughHandler:def test_join_url_paths(self):print("\nTesting _join_url_paths method...")