Repository navigation
fix(vertex_ai): send service_tier to Vertex Gemini as tier headers (#34959) [lts/1.108.x] - #53428
Conversation
…ement The serviceTier body field is accepted by Vertex AI (no 400) but does not activate tier routing. The X-Vertex-AI-LLM-Shared-Request-Type header is what actually routes to shared rate-limit pools with priority/flex enforcement. Changes: - validate_environment(): inject X-Vertex-AI-LLM-Request-Type and X-Vertex-AI-LLM-Shared-Request-Type headers when service_tier is priority or flex (Vertex AI only, not Google AI Studio) - _transform_request_body(): skip serviceTier in body for Vertex AI (keep for Google AI Studio gemini/ where body field works) - _map_service_tier_param(): normalize prefixed values (SERVICE_TIER_FLEX -> flex), skip non-routing tiers (auto, default, scale, unspecified) See: BerriAI#34914 (cherry picked from commit 4f4c0ba)
…uff gate (cherry picked from commit e1aed51)
(cherry picked from commit 81756c0)
Vertex rejects a lowercase serviceTier body field with a 400, so priority and flex now go out as the X-Vertex-AI-LLM-Request-Type and X-Vertex-AI-LLM-Shared-Request-Type headers. AI Studio keeps the body field. auto, default, scale and unspecified send no tier instead of turning into priority, and an unknown tier answers 400 unless drop_params is set. (cherry picked from commit 68348e6)
…p standard_only to standard (cherry picked from commit cd73861)
The tier tests now seed the Vertex credential cache instead of patching VertexBase, and they cover an upper-case caller tier header and the SERVICE_TIER_STANDARD_ONLY spelling (cherry picked from commit 044c09d)
…rtex tier, reject batch tiers AI Studio keeps sending auto as priority, as its docs promise. Vertex sends only the shared request type header so provisioned throughput is used first, reads the served tier from trafficType, answers 400 to unknown tiers like scale, and batch rows with a tier answer 400 unless drop_params is set (cherry picked from commit f9d363b)
…n responses rows A Vertex batch row now answers 400 only for priority and flex, the tiers real-time Vertex sends as a header, so standard uploads with no tier like default and auto. A /v1/responses batch row keeps its drop_params when it is bridged to a chat body, so drop_params drops the tier there too (cherry picked from commit 96fd436)
… AI Studio default, and report Provisioned Throughput as default (cherry picked from commit 1e00622)
[Medium impact] The PR appears safe to merge with no new actionable findings
|
… MCP tools in batch rows The line's batch row builder passed drop_params=False to map_openai_params, so a row's or deployment's drop_params never reached the service_tier check or the hosted MCP tool filter. Pass the resolved value, as main does.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…rt_34959_lts_1_108_x # Conflicts: # litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py
… keep deployment drop_params on file uploads
…rt_34959_lts_1_108_x
…rt_34959_lts_1_108_x # Conflicts: # litellm/llms/gemini/chat/transformation.py
…rt_34959_lts_1_108_x # Conflicts: # tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 2f66d37. Configure here.
On the 1.108 LTS line, Vertex Gemini answers 400 to every
service_tiervalue, since litellm sends a bodyserviceTierfield that Vertex rejectsThis brings the same fix as #34959 to the line
Details
TLDR
Problem this solves:
service_tiervalue, since litellm sends a bodyserviceTierfield that Vertex rejectsautoturned intopriority, andSERVICE_TIER_FLEXstyle values reached Vertex unchangedHow it solves it:
priorityandflexas theX-Vertex-AI-LLM-Shared-Request-Typeheader, so Provisioned Throughput is used firstgemini/) keeps theserviceTierbody field, andautostill maps toprioritythere, as beforeauto,defaultandstandardsend no tier, andstandard_onlymeansstandardusageMetadata.trafficTypeservice_tierscaleanswers 400 unlessdrop_paramsis set, and so doespriorityorflexon a Vertex batch rowdrop_paramsnow drops an unknown tier and hosted MCP tools, as on mainBackport checklist
cherry-pick -x, as the table below lists. Every pick changes the same lines as its main commit except60716324b5andacc59f5e6a. In60716324b5the line lacked main's deploymentdrop_paramsplumbing for batch rows (_map_openai_to_vertex_params(deployment_drop_params=...)and thepartialthat passes it), so the pick brings that plumbing over as main has it, and leaves out two main-only tests for thinking levels and TTS voice keys. Inacc59f5e6athe batch row builder keeps the line'sopenai_request_bodyname, and_map_traffic_type_to_service_tierkeeps the line'sobjectparameter typedrop_params=Falsetomap_openai_params, so a row's or deployment'sdrop_paramsnever reached the tier check or the hosted MCP tool filter, andcfef3edae2passes the resolved value, as fix(vertex_ai): send service_tier to Vertex Gemini as tier headers #34959 does on main. The line's stream wrapper built thefinish_reasonchunk without the tier the earlier chunks carried, and11b09d19fftakes the last tier the stream reported, as main does. The line's/v1/filesupload with amodelalso kept the deployment'sdrop_paramsout of the request, and11b09d19ffmerges it in, as main does since feat(vertex-ai)!: support gemini 3.1 flash tts #31915.d48a603fba,6ac64d9a8b,3941eae668and2f66d37300merge the line, the last at9fca0777db, and three of them resolve a small conflict eachtrafficTypetable, atacc59f5e6a), and the new cases fail without the fix. Atcfef3edae2the 12 unit test files that import the changed module pass, run with the batch and Vertex Gemini test folders (3518 passed), and its 3 new batch row cases fail without it. At11b09d19ffthe 517 affected test files pass, apart from 29 flakes that pass alone and one clock-dependent test that fails on the line too, and its 6 new stream cases and 2 upload cases fail without it. At2f66d37300the PR's test folders pass (3788 passed)enterprise/orlitellm-proxy-extras/change, so no package bump63bb90b5c2and90922104c2. Its findings were fixed on main and are in the later pickscfef3edae2and11b09d19ffpass /live-pr-risk4f4c0ba0bfe1e7a6f81be1aed51992e1e01b619d81756c0c986a979084db68348e680ed834a09ef9cd7386182690922104c2044c09d9a64204f74fcdf9d363b18b60716324b596fd436be38daaaaf4281e00622b2dacc59f5e6aUser Flow
Before: a developer asking Vertex Gemini for the priority tier gets a 400 instead of an answer
vertex_ai/gemini-3.8-flashto config.yaml and starts the proxy"service_tier": "priority"Invalid value at 'service_tier'After: the same request is served at the asked tier, and the response says which tier
vertex_ai/gemini-3.8-flashto config.yaml and starts the proxy"service_tier": "priority""service_tier": "priority", and thex-litellm-response-costheader shows the priority rateautoanswers 200 with"service_tier": "default"at the standard rate, and"scale"answers 400 listing the allowed valuesRelevant issues
Backport of #34959 for #34914
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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 smoke per fix, with real calls to Vertex AI (
global) and Google AI Studio ongemini-3.8-flash, 2 uvicorn workers per proxy and no database. Before islts/1.108.xat2e46e4c77f, and After isacc59f5e6a. The line is now at9fca0777db, merged in2f66d37300, and the newest stream legs include its #53441 stream fix. Eachsent:line is what a recorder in front of Google sawprioritypriority, priority rateflexflex, flex rateautodefault, standard ratestandard_onlydefaultscalepriority,flexpriorityflex, flex rateautopriorityprioritydefaultstandardstandardpriorityserviceTier: prioritydrop_paramsserviceTier: prioritystandardserviceTier: standardscaleserviceTier: scalescale,drop_paramsserviceTier: scaledrop_paramsSmoke at the line tip `9fca0777db` (Before) and the merge `2f66d37300` (After), same proxy setup and helpers as below, plus `chat_tier`
The Before
tier_chunksleg prints empty lists because Vertex answered 400, which itsstreamGenerateContentsent:line showsBoth legs load the same Rust bridge build from an earlier line commit. The line's newer Rust change is in the Vertex
/v1/messagestransform, which none of these cases callBatch rows read back from GCS at the line tip `9fca0777db` (Before) and the merge `2f66d37300` (After)
Each upload names
vertex-batchorvertex-batch-drop(drop_params: trueon the deployment).lpr-priority.jsonlis one chat row with"service_tier": "priority",lpr-priority-drop.jsonladds"drop_params": trueto the row, andlpr-standard.jsonlasks forstandard.rows.pyreads the uploaded object from GCS with the same service account and prints the row's top-level keys. Before, every row keepsserviceTier, even underdrop_params, so the row reaches the job with the field. #34959's batch job leg shows such a row failing inside Vertex withunknown enum value. After,prioritywithoutdrop_paramsis a 400 at upload, and the other rows carry no tierBefore (2e46e4c)
Chat
Output
Batch upload
POST /v1/filesandcustom-llm-provider: vertex_aiOutput
After (acc59f5)
Chat
Output
Batch upload
Output
Then a batch job from each uploaded file, through
POST /v1/batchesandGET /v1/batches/<id>. All three complete. The line'sGET /v1/files/<id>/contentrefuses raw Cloud Storage ids, so the rows are not read back here, and #34959 shows them on mainNon-pick commit (cfef3ed)
Before is the merge base
7ab941f451, oracc59f5e6afor the hosted MCP rows, which passesdrop_params=Falsethere too. After iscfef3edae2. Uploaded rows are read back from Cloud Storage withrows.pybelow, since the line's/v1/files/<id>/contentrefuses raw idsSetup (config.yaml, proxy start, curl helpers)
Env vars:
GOOGLE_APPLICATION_CREDENTIALS,VERTEXAI_PROJECT,GEMINI_API_KEY,LITELLM_MASTER_KEY,GCS_BATCH_BUCKET_NAME, andREC_BASE/REC_STUDIO_BASEfor the recorders.vertex-batchcomes first so/v1/fileswithcustom-llm-provider: vertex_aiuses a deployment with no recorder in front of Cloud StorageEach batch file is one row,
{"custom_id":"r-1","method":"POST","url":"/v1/chat/completions","body":{"model":"gemini-3.8-flash","messages":[{"role":"user","content":"Say hello in one word."}],"max_tokens":20,...}}, with the extra fields its name says. The/v1/responsesrows sendinputandmax_output_tokensinstead. The MCP rows send aget_timefunction tool and{"type":"mcp","server_label":"deepwiki","server_url":"https://mcp.deepwiki.com/mcp","require_approval":"never"}Stream
Before (7ab941f)
The recorder saw
body_serviceTierpriorityandflex, no tier header, and a 400 from VertexAfter (cfef3ed)
The recorder saw
x-vertex-ai-llm-shared-request-typepriorityandflex, no bodyserviceTier, and a 200 from Vertex. Thenullis thefinish_reasonchunk, which11b09d19fffillsBatch rows with
scaleBefore (7ab941f)
After (cfef3ed)
Batch rows that reach the changed call (/live-pr-risk)
Only the four
drop_paramsrows differ, and every other row answers the same on bothOutput, Before (acc59f5) then After (cfef3ed)
Rows read back from Cloud Storage, After
Deployment
drop_paramson batch rowsOutput, Before (acc59f5) then After (11b09d1)
The upload names its deployment with
-F model=, and the rows carry nodrop_paramsof their own.vertex-batch-dropisvertex-batchwithdrop_params: true, and the setup is in the next sectionBefore
After
Rows read back from Cloud Storage, After
OpenAI file uploads through a deployment with
drop_params: true(openai-batch-drop) answer the same, Before (d48a603)After
Vertex Claude rows (
vertex-claude-batch-drop) on the line at67c4edeaa8, Before (6ac64d9a8bwithout the upload change)After (
6ac64d9a8b)Non-pick commit (11b09d1)
Before is
d48a603fbaand After is11b09d19ffprioritynullprioritynulldefaultfake_streamSetup added to the config and helpers above
Env vars
OPENAI_API_KEYandANTHROPIC_API_KEYtooOutput, Before (d48a603)
Output, After (11b09d1)
Type
🐛 Bug Fix
Caveats (if any)
Copied from #34959
Medium
SERVICE_TIER_FLEXandSERVICE_TIER_PRIORITYanswered 200 at the standard tier before. They now run on Flex or Priority, so the bill changes, and Vertex answers 400 where the region or model lacks the tier, pastdrop_params. Use theglobalendpoint ordefaultLow
priorityorflexnow answer 400 at upload unlessdrop_paramsis set, where before each row failed inside the jobdefaultwhere they saidnullorNonegemini/andvertex_ai/deployments billsautoat priority on AI Studio and at standard on VertexdedicatedRequest-Type header with aservice_tieris untested live, since it needs Provisioned Throughput/v1/responsesand/v1/messagesreturnservice_tier: nullon every Gemini route, as beforeservice_tiernow answers 400 unlessdrop_paramsis set, as OpenAI doeslitellm.drop_params, a module global with no injection pointDecisions
autoon Vertex sends no tier, so Vertex serves its standard tier. On AI Studioautostill sendspriority, since litellm's Gemini docs promise that and a change would silently move AI Studio callers to the standard rate. Rejected: one meaning for both routesX-Vertex-AI-LLM-Shared-Request-Typeis sent, so a project with Provisioned Throughput uses it first and spills over to the asked tier. Rejected: also sendingX-Vertex-AI-LLM-Request-Type: shared, which skips Provisioned Throughput the customer already pays for. A caller who wants pay-as-you-go only can send that header, and litellm keeps itscaleanswers 400 unlessdrop_paramsis set, per litellm'sdrop_paramsrule. Rejected: treating it as standardflexon a model without it. Google's docs say Flex runs only on theglobalendpoint and on some models, and Priority onglobal,us, andeu. Rejected: a litellm copy of that matrix, which goes stale as Google adds regions and models, and sendingstandardinstead, which bills a tier the caller did not ask forpriorityorflexon a Vertex batch row answers 400 unlessdrop_paramsis set, since batch jobs run on the batch tier and take no tier header, whilestandard,default, andautoupload with no tier, as on real-time Vertex calls. Rejected: dropping every tier silentlytrafficTypethrough the table cost uses, soON_DEMAND, Provisioned Throughput and any unknown value reportdefault, the tier cost bills. Rejected:nullfor Provisioned Throughput, which left the response and the Prometheus label apart from the bill, and leavingservice_tiernull for every Vertex responsedefaultsendsserviceTier: "standard", as it did before this PR. Rejected: sending no tier, which changed what AI Studio got for no fixFinal Attestation
Bugbot summary