Skip to content

fix(vertex_ai): route xai/grok through completion adapter on generateContent - #42272

Closed
Rainmemery wants to merge 3 commits into
BerriAI:mainfrom
Rainmemery:fix/vertex-grok-generate-content-route
Closed

Rainmemery wants to merge 3 commits into
BerriAI:mainfrom
Rainmemery:fix/vertex-grok-generate-content-route

Conversation

@Rainmemery

Copy link
Copy Markdown

TLDR

POST /v1beta/models/{model}:generateContent (the unified Gemini-style proxy endpoint) treats vertex_ai/xai/grok-* as a native Gemini model and fails with a protocol mismatch, while /v1/chat/completions on the same deployment works fine.

Root cause: ProviderConfigManager.get_provider_google_genai_generate_content_config() only falls back to the litellm.completion() adapter when VertexAIPartnerModels.is_vertex_partner_model() is true, and PartnerModelPrefixes has no xai/ entry. So xai/grok-* is handed to VertexAIGoogleGenAIConfig, which translates it as a Gemini call and the request breaks.

Fix: xai/ publisher models are Model Garden OpenAI-compatible (see get_vertex_ai_model_route() → MODEL_GARDEN). Route them through the completion adapter on the Gemini-style endpoint, the same way openai/gpt-oss-, moonshotai/, minimaxai/, zai-org/, google/gemma- are already handled.

How it works

  • /v1beta/models/{model}:generateContent with vertex_ai/xai/grok-* now returns None from get_provider_google_genai_generate_content_config(), which makes the generate_content setup take the adapter path (GenerateContentToCompletionHandler) → translated into a chat-completions call → get_vertex_ai_model_route() dispatches to the Model Garden OpenAI-compatible handler.
  • Native gemini-* models are unaffected (still get VertexAIGoogleGenAIConfig).

Tests

  • test_get_provider_google_genai_generate_content_config_vertex_partner_models in tests/test_litellm/test_utils.py — asserts xai/grok-* → None (adapter), partner models unchanged, gemini-1.5-pro → VertexAIGoogleGenAIConfig.

…Content

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>
@codspeed

codspeed Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing Rainmemery:fix/vertex-grok-generate-content-route (adf523d) with main (f4308bc)

Open in CodSpeed

@Rainmemery

Copy link
Copy Markdown
Author

CI status: 88/92 check-runs green. The only failure is proxy-endpoints / Run tests, which dies at Save coverage report ? Failed to FinalizeArtifact: 403 Forbidden - the same GitHub Actions Node-20 / artifact-upload infra issue affecting several other contributor PRs (e.g. #42218, #42237); the test partition itself has no code-related annotations. All unit tests for the change pass locally under the CI configs (ruff.toml / ruff-tests.toml).

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Rainmemery

Copy link
Copy Markdown
Author

Note on the codecov/patch 0% flag: the 2 'missing' lines are exactly the new branch in litellm/utils.py, and they are covered by the regression test added in this PR - but that coverage is reported missing because the proxy-endpoints / Run tests shard fails at its Save coverage report step with the same FinalizeArtifact: 403 infra error, so its coverage upload never lands. Verified locally with pytest-cov (the added lines do not appear in the missing list). Same repo-wide infra issue as #42263/#42218.

@Rainmemery

Copy link
Copy Markdown
Author

Status update: CI is complete — 91/93 checks green. The only two failures are the known repo-level infra issues: codecov/patch (coverage not uploaded to this fork-run, the 2 added lines are covered by the new regression test locally) and proxy-endpoints / Run tests which dies at the Save coverage report step (Failed to FinalizeArtifact, Node-20/artifacts infra). No code-related failures remain. This was opened as a draft because the create endpoint defaults to draft for first-time PRs; code and tests are complete and ready for review.

Resolve the test_litellm/test_utils.py conflict by keeping both this PR's Vertex Grok generateContent test and main's new request-logging tests. litellm/utils.py auto-merged; the xai/ -> completion-adapter route is intact.
@Rainmemery

Copy link
Copy Markdown
Author

Hi maintainers 👋 — this PR is ready for a re-approve whenever you have a moment. Just merged latest main in to clear the previous merge conflict; it's now mergeable and CI is green except for one unrelated check.

The only red check is rust-test, which is not caused by this change:

  • The diff is Python-only — it touches just litellm/utils.py (+13/-0) and tests/test_litellm/test_utils.py (+47/-0), and does not modify anything under litellm-rust/. rust-test runs cargo nextest, so a Python change here cannot affect it (it's only triggered because litellm/utils.py is in the workflow's path filter).
  • All the previously-flaky items are now green: proxy-endpoints / Run tests, its coverage upload, and lint / rust-lint / frontend-lint.
  • On the latest commits merged into main, rust-test is mostly no-run yet those PRs still merged — so it doesn't appear to be a required check. A comparable PR (fix(model-catalog): declare above_32k cost fields on ModelInfo #42856), sharing the same Rust tree as this branch's merge base, had rust-test pass ~10 min after our run failed.

The failure annotation is exit code 100 from cargo-nextest; I don't have write access to re-run the workflow. Could a maintainer please kick off a Re-run of the rust-test job? It looks like a pre-existing/flaky failure rather than something introduced here.

Happy to adjust anything — thanks for your time! 🙏

@mateo-berri

Copy link
Copy Markdown
Contributor

Thanks for this. #41836 fixes the same selector through get_vertex_ai_model_route, so we are merging that one and closing this as superseded

@Rainmemery

Copy link
Copy Markdown
Author

Thanks for the update — happy to have this closed as superseded by #41836.

I checked the diff: #41836 covers the same selector with the parametrized case (xai/grok-* and the other non-Google Model Garden families falling through to the completion adapter, native Gemini keeping the Google Gen AI config), so there is nothing worth porting over from here. Closing it out now.

@Rainmemery Rainmemery closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants