Skip to content

fix(vertex_ai): send extra_body fields as predict parameters for BGE embedding models - #51662

Merged
kerry-berri merged 2 commits into
mainfrom
litellm_vertex_bge_extra_body
Nov 15, 2026
Merged

kerry-berri merged 2 commits into
mainfrom
litellm_vertex_bge_extra_body

Conversation

@kerry-berri

@kerry-berri kerry-berri commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

Link to Devin session: https://app.devin.ai/sessions/d77a3c28f4084c7cb8c2a6bc18ead1f0
Open in Devin Desktop: https://app.devin.ai/desktop/session/d77a3c28f4084c7cb8c2a6bc18ead1f0?variant=devin
Requested by: @kerry-berri

TLDR

Problem this solves:

  • Vertex BGE embeddings send extra_body nested as parameters.extra_body
  • Every other Vertex text embedding model sends those fields flat

How it solves it:

  • The BGE request builder reuses split_extra_body, like its siblings
  • extra_body fields land directly under parameters

User Flow

Before: a developer who passes a raw Vertex field through extra_body to a BGE embedding model never gets it applied

  1. They send POST https://litellm-domain/v1/embeddings with a vertex_ai/bge-small-en-v1.5 model and "extra_body": {"autoTruncate": false}
  2. The call returns 200 with embeddings
  3. The predict request that reached Vertex carried "parameters": {"extra_body": {"autoTruncate": false}}, so the field sat under a key the endpoint does not read

After: the same request delivers the field where the endpoint reads it

  1. They send the same POST https://litellm-domain/v1/embeddings with "extra_body": {"autoTruncate": false}
  2. The call returns 200 with embeddings
  3. The predict request that reached Vertex carried "parameters": {"autoTruncate": false}, the same shape text-embedding-005 already gets

Relevant issues

Follow-up to #51335, which unwrapped extra_body for the other Vertex text embedding paths.

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

One live proxy per leg, one worker, no Redis and no database, because the change is in the outbound request body only. The Google access token is real, minted from the service account in VERTEX_AI_DEVIN_SERVICE_ACCOUNT_JSON. The predict endpoint is a local capture server set as api_base, because the QA project has no deployed BGE endpoint. It prints the body it received and answers with one BGE-shaped prediction.

Proxy command, run from the checkout under test

LITELLM_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=true python -m litellm.proxy.proxy_cli --config config.yaml --port 4801 --num_workers 1

config.yaml (env vars VERTEXAI_PROJECT, VERTEX_AI_DEVIN_SERVICE_ACCOUNT_JSON)

model_list:
  - model_name: bge
    litellm_params:
      model: vertex_ai/bge-small-en-v1.5
      api_base: http://127.0.0.1:18801
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-central1
      vertex_credentials: os.environ/VERTEX_AI_DEVIN_SERVICE_ACCOUNT_JSON
general_settings:
  master_key: sk-1234
capture.py, started with python3 capture.py 18801
import json, sys
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
    def do_POST(self):
        body = self.rfile.read(int(self.headers["content-length"]))
        print("UPSTREAM", self.path, body.decode(), flush=True)
        out = json.dumps({"predictions": [[0.1, 0.2, 0.3]]}).encode()
        self.send_response(200); self.send_header("content-type", "application/json"); self.send_header("content-length", str(len(out))); self.end_headers(); self.wfile.write(out)
    def log_message(self, *a): pass
HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()

Client command, the same on both legs

curl -s localhost:4801/v1/embeddings -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"bge","input":["hello"],"extra_body":{"autoTruncate":false}}'

Before (7a72c2b)

  1. The curl returns 200 with "embedding":[0.1,0.2,0.3]
  2. The capture server printed
UPSTREAM /v1/projects/<project>/locations/us-central1/publishers/google/models/bge-small-en-v1.5:predict {"instances":[{"prompt":"hello"}],"parameters":{"extra_body":{"autoTruncate":false}}}

After (1a56189)

  1. The curl returns 200 with "embedding":[0.1,0.2,0.3]
  2. The capture server printed
UPSTREAM /v1/projects/<project>/locations/us-central1/publishers/google/models/bge-small-en-v1.5:predict {"instances":[{"prompt":"hello"}],"parameters":{"autoTruncate":false}}

Tests. tests/integration/providers/test_vertex_embedding_wire.py::test_vertex_bge_embedding_sends_extra_body_fields_as_predict_parameters fails on 7a72c2b with the nested body and passes at the tip (INTEGRATION_WORKERS=2 python tests/integration/run.py providers tests/integration/providers/test_vertex_embedding_wire.py, 5 passed). The unit test test_vertex_embedding_call_sends_extra_body_fields_as_predict_parameters gained a bge case that fails on main and passes at the tip. The integration file first runs in CI on main after merge.

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Proof used a local predict endpoint, no deployed BGE endpoint was available
  • How a real BGE endpoint treats the old nested key was not observed

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Low Risk
Scoped outbound request shaping for BGE embeddings only; aligns behavior with existing Vertex embedding handlers and is covered by wire and unit tests.

Overview
Vertex BGE embedding requests now flatten extra_body into top-level parameters, matching Gecko and other Vertex text embedding paths instead of nesting under parameters.extra_body.

VertexBGEConfig.transform_request adopts split_extra_body and merges the result into EmbeddingParameters the same way as transformation.py. Integration and unit tests assert BGE predict payloads use instances with prompt and bare fields like autoTruncate on parameters.

Reviewed by Cursor Bugbot for commit 320c5a3. Bugbot is set up for automated code reviews on this repo. Configure here.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@veria-ai

@veria-ai

veria-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no new actionable issues found.

Summary

BGE embedding requests now put fields from extra_body directly under parameters, matching the other Vertex text embedding paths.

The added unit and integration tests check the outgoing request shape. No new actionable issues were found.

kerry-berri accepted the live-provider QA gap because the QA project has no deployed BGE endpoint. The supplied proof instead captures the outgoing request.

  • Vertex BGE requests now send extra_body fields as predict parameters.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into litellm_vertex_..." · Reviewed by Greptile

Comment on lines +88 to +92
body_params, extra_body = split_extra_body(optional_params)
vertex_request["parameters"] = (
cast( # cast-ok: extra_body carries raw Vertex fields the TypedDict does not list
EmbeddingParameters, {**extra_body, **body_params}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Required live proof is missing

This changes how BGE receives extra_body fields, but the supplied proof uses a local capture server. The repository requires before/after proxy requests against real providers. Supply qualifying before proof and after proof at 1a561897c14f7d9b70f07dccfe631a1d7b522a74 before merging.

Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebuttal, the QA project has no deployed BGE endpoint, so the proof captures the exact outbound predict body, the only thing this change alters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the constraint, and the capture test is useful evidence that LiteLLM emits the intended request body. But because the request is redirected to a local server that fabricates the response, it does not verify that Vertex accepts or applies the flattened autoTruncate parameter. The required proof is a proxy request to the real Vertex API, with before-and-after runs (before on the PR base; after on latest product commit 1a561897c14f7d9b70f07dccfe631a1d7b522a74), including reproducible commands and actual outputs. The lack of a deployed BGE endpoint explains the gap, but does not make the capture-server run equivalent. Please provide that proof or get a maintainer exception to the live-QA requirement.

@codspeed

codspeed Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 45 untouched benchmarks


Comparing litellm_vertex_bge_extra_body (320c5a3) with main (09ce4f5)

Open in CodSpeed

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@veria-ai

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 320c5a3. Configure here.

@kerry-berri
kerry-berri enabled auto-merge (squash) November 15, 2026 18:27
@kerry-berri
kerry-berri merged commit 2d487ab into main Nov 15, 2026
102 of 103 checks passed
@kerry-berri
kerry-berri deleted the litellm_vertex_bge_extra_body branch November 15, 2026 19:30
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.

3 participants