From 650b78256bd0903780bb0a86d6e86d7c74cd68db Mon Sep 17 00:00:00 2001 From: Manjunath S Date: Mon, 30 Mar 2026 18:03:22 +0530 Subject: [PATCH] fix(gemini): prevent duplicate model path generation when api_base includes full route --- litellm/llms/vertex_ai/vertex_llm_base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index 1a29ba82eac..6763626b2fd 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -393,7 +393,12 @@ class VertexBase: raise ValueError( "Model parameter is required for Gemini custom API base URLs" ) - url = "{}/models/{}:{}".format(api_base, model, endpoint) + if api_base.endswith(f"/models/{model}:{endpoint}"): + url = api_base + elif api_base.endswith(f"/models/{model}"): + url = f"{api_base}:{endpoint}" + else: + url = "{}/models/{}:{}".format(api_base.rstrip("/"), model, endpoint) if gemini_api_key is None: raise ValueError( "Missing gemini_api_key, please set `GEMINI_API_KEY`"