Skip to content

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]

fix(vertex_ai): return create_vertex_url result directly for openai-path partner models with custom api_base (#32380)

Mateo Wang46d974295055
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",
[