From 3e8bbdeefee467c0dca0152ab1f02d315f483ef6 Mon Sep 17 00:00:00 2001 From: gambletan Date: Fri, 13 Mar 2026 13:34:10 +0800 Subject: [PATCH] fix: route vertex_ai gemini-embedding-* models to embedContent endpoint When get_model_info() fails to find uses_embed_content for a model (e.g. due to missing/stale model cost map), fall back to checking the model name prefix. All gemini-embedding-* models require the embedContent endpoint, not the legacy :predict endpoint which returns 400 FAILED_PRECONDITION for gemini-embedding-2-preview. Fixes #23508 Co-Authored-By: Claude Opus 4.6 --- litellm/llms/vertex_ai/common_utils.py | 5 +++++ litellm/main.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.py index 5895a91f3aa..71b3b2babcd 100644 --- a/litellm/llms/vertex_ai/common_utils.py +++ b/litellm/llms/vertex_ai/common_utils.py @@ -263,6 +263,11 @@ def _get_embedding_url( except Exception: uses_embed_content = False + # Fallback: all gemini-embedding-* models require the + # embedContent endpoint, not the legacy :predict endpoint. + if not uses_embed_content and model.startswith("gemini-embedding"): + uses_embed_content = True + endpoint = "embedContent" if uses_embed_content else "predict" base_url = get_vertex_base_url(vertex_location) diff --git a/litellm/main.py b/litellm/main.py index f2ce894ba38..ac7499ea415 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -5204,6 +5204,11 @@ def embedding( # noqa: PLR0915 except Exception: uses_embed_content = False + # Fallback: all gemini-embedding-* models require the + # embedContent endpoint, not the legacy :predict endpoint. + if not uses_embed_content and model.startswith("gemini-embedding"): + uses_embed_content = True + if uses_embed_content: response = google_batch_embeddings.batch_embeddings( # type: ignore model=model,