From 46d9742950552d15fac35c88e4f67040c799d2a2 Mon Sep 17 00:00:00 2001 From: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 7 Jul 2026 14:49:21 -0700 Subject: [PATCH] fix(vertex_ai): return create_vertex_url result directly for openai-path partner models with custom api_base (#32380) --- litellm/llms/vertex_ai/vertex_llm_base.py | 3 + .../llms/vertex_ai/test_vertex_llm_base.py | 73 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index e177d06bb01..788261ac1fe 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -316,6 +316,9 @@ class VertexBase: api_base=api_base, ) + if partner == VertexPartnerProvider.llama: + return default_api_base + if len(default_api_base.split(":")) > 1: endpoint = default_api_base.split(":")[-1] else: diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py b/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py index ffe935a52af..18fc239b7c6 100644 --- a/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py +++ b/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py @@ -15,6 +15,7 @@ sys.path.insert( import litellm from litellm.llms.vertex_ai.vertex_ai_aws_wif import VertexAIAwsWifAuth from litellm.llms.vertex_ai.vertex_llm_base import VertexBase +from litellm.types.llms.vertex_ai import VertexPartnerProvider def run_sync(coro): @@ -1025,6 +1026,78 @@ class TestVertexBase: assert result_url == "https://10.96.32.8/v1/projects/test-project/locations/us-central1/endpoints/1234567890:predict" + @pytest.mark.parametrize( + "custom_api_base, stream, expected_url", + [ + ( + "https://aiplatform-myendpoint.p.googleapis.com", + False, + "https://aiplatform-myendpoint.p.googleapis.com/v1/projects/test-project/locations/global/endpoints/openapi/chat/completions", + ), + ( + "https://aiplatform-myendpoint.p.googleapis.com", + True, + "https://aiplatform-myendpoint.p.googleapis.com/v1/projects/test-project/locations/global/endpoints/openapi/chat/completions", + ), + ( + "https://gateway.example.com/vertex-proxy", + False, + "https://gateway.example.com/vertex-proxy/v1/projects/test-project/locations/global/endpoints/openapi/chat/completions", + ), + ], + ids=["psc-host", "psc-host-streaming", "api-base-with-path"], + ) + def test_get_complete_vertex_url_openai_path_partner_custom_api_base( + self, custom_api_base, stream, expected_url + ): + vertex_base = VertexBase() + + result = vertex_base.get_complete_vertex_url( + custom_api_base=custom_api_base, + vertex_location="global", + vertex_project="test-project", + project_id="test-project", + partner=VertexPartnerProvider.llama, + stream=stream, + model="minimaxai/minimax-m2-maas", + ) + + assert result == expected_url + assert result.count("://") == 1 + + def test_get_complete_vertex_url_openai_path_partner_default_api_base(self): + vertex_base = VertexBase() + + result = vertex_base.get_complete_vertex_url( + custom_api_base=None, + vertex_location="us-central1", + vertex_project="test-project", + project_id="test-project", + partner=VertexPartnerProvider.llama, + stream=True, + model="meta/llama-3.1-405b-instruct-maas", + ) + + assert ( + result + == "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/endpoints/openapi/chat/completions" + ) + + def test_get_complete_vertex_url_rawpredict_partner_custom_api_base_keeps_endpoint_format(self): + vertex_base = VertexBase() + + result = vertex_base.get_complete_vertex_url( + custom_api_base="https://gateway.example.com/vertex-proxy", + vertex_location="us-central1", + vertex_project="test-project", + project_id="test-project", + partner=VertexPartnerProvider.mistralai, + stream=False, + model="mistral-large-2411", + ) + + assert result == "https://gateway.example.com/vertex-proxy:rawPredict" + @pytest.mark.parametrize( "api_base, custom_llm_provider, gemini_api_key, endpoint, stream, auth_header, url, model, expected_auth_header, expected_url", [