From 843189740bbc7e30bad1449c8cf9d810a6afb330 Mon Sep 17 00:00:00 2001 From: Rainmemery <152621457+Rainmemery@users.noreply.github.com> Date: Mon, 21 Sep 2026 18:33:05 +0000 Subject: [PATCH] fix(vertex_ai): route xai/grok through completion adapter on generateContent POST /v1beta/models/{model}:generateContent treated vertex_ai/xai/grok-* as a native Gemini model: get_provider_google_genai_generate_content_config() only falls back to the litellm.completion() adapter for Vertex Partner models, and PartnerModelPrefixes has no xai/ entry. Grok is dispatched to VertexAIGoogleGenAIConfig and fails with a protocol mismatch. xai/ publisher models are Model Garden OpenAI-compatible, matching how get_vertex_ai_model_route() already serves them (MODEL_GARDEN). Route them through the completion adapter on the unified Gemini-style endpoint, the same way openai/gpt-oss-, moonshotai/, minimaxai/, etc. are handled. Signed-off-by: Rainmemery <152621457+Rainmemery@users.noreply.github.com> --- litellm/utils.py | 13 +++++++++ tests/test_litellm/test_utils.py | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 252bc691301..b4f8e5b0d86 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -9767,6 +9767,19 @@ class ProviderConfigManager: if VertexAIPartnerModels.is_vertex_partner_model(model): return None + ######################################################### + # Model Garden publisher models served via the OpenAI-compatible + # route (e.g. xai/grok-*) are not Vertex Partner "raw" models, but + # they still go through the litellm.completion() adapter (which + # dispatches them to the Model Garden OpenAI-compatible handler), + # never through the Google Gen AI config. Without this case the + # unified Gemini-style endpoint POST /v1beta/models/{model}:generateContent + # would treat e.g. vertex_ai/xai/grok-* as a native Gemini model + # and fail with a protocol mismatch. + ######################################################### + if model.startswith("xai/"): + return None + ######################################################### # If the model is not a Vertex Partner model, return the Vertex AI Google Gen AI Config # This is for Vertex `gemini` models diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index 7a7d5d44e95..24900c27877 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -5796,3 +5796,49 @@ def test_calculate_max_parallel_requests_precedence( ) == expected ) + +def test_get_provider_google_genai_generate_content_config_vertex_partner_models(): + """ + https://github.com/BerriAI/litellm/issues/41835 + Vertex Grok (vertex_ai/xai/grok-*) is rejected on /v1beta/models/{model}:generateContent + because get_provider_google_genai_generate_content_config() only falls back to the + litellm.completion() adapter for Vertex Partner models, and xai/ was missing from + PartnerModelPrefixes. Ensure xai/grok-* now returns None (i.e. the generateContent + endpoint routes it through the chat-completions adapter like other Model Garden + OpenAI-compatible partners), while gemini models still get the native config. + """ + from litellm.types.utils import LlmProviders + + # Grok via Model Garden -> through the completion adapter (None) + assert ( + ProviderConfigManager.get_provider_google_genai_generate_content_config( + model="xai/grok-4.6", provider=LlmProviders.VERTEX_AI + ) + is None + ) + assert ( + ProviderConfigManager.get_provider_google_genai_generate_content_config( + model="xai/grok-4.1-fast-non-reasoning", provider=LlmProviders.VERTEX_AI + ) + is None + ) + + # Other existing partner models are unaffected + assert ( + ProviderConfigManager.get_provider_google_genai_generate_content_config( + model="claude-3-5-sonnet-20241022", provider=LlmProviders.VERTEX_AI + ) + is None + ) + + # Native Gemini models still get the Vertex Google Gen AI config + from litellm.llms.vertex_ai.google_genai.transformation import ( + VertexAIGoogleGenAIConfig, + ) + + assert isinstance( + ProviderConfigManager.get_provider_google_genai_generate_content_config( + model="gemini-1.5-pro", provider=LlmProviders.VERTEX_AI + ), + VertexAIGoogleGenAIConfig, + )