Repository navigation
fix(bedrock): send Converse extra_body fields instead of a literal extra_body object - #50964
norkelbyte wants to merge 5 commits into
Conversation
…tra_body object Bedrock Converse got the whole extra_body object as one additionalModelRequestFields entry and answered 400 "Unknown parameter: 'extra_body'", with or without drop_params. The fields inside extra_body are now merged into the request params the same way top-level fields are, with extra_body winning a name clash. A non-object extra_body is dropped under drop_params and answers 400 without it.
PR overviewThe PR changes Bedrock Converse request transformation to send extra_body fields directly rather than nesting them inside a literal extra_body object. One issue remains open: an extra_body output-token override can raise the limit sent to Bedrock above the value used for proxy and router admission checks. This allows concurrent requests to exceed configured token-per-minute limits before usage reconciliation, weakening quota enforcement and potentially increasing consumption. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 Reviews |
[Medium impact] The PR appears safe to merge, with all previous findings addressed and no new actionable issues found. SummaryThe PR sends fields inside
All three previous findings are addressed. No new actionable issues were found. Reviews (2) · Last reviewed commit: "Merge origin/main into litellm_bedrock_c..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… checks Tools or guardrailConfig sent only inside extra_body are now seen by the orphaned tool block and guarded text checks, and an extra_body output_config gets the same effort cap as a top-level one. The merge builds a new dict, so the caller's params keep neither the fields nor the internal marker
Main now passes the guarded text call a keeps_cache_marks flag computed from the params. The cache mark checks read the params after the extra_body merge, so a guardrailConfig or tools inside extra_body count the same as top level ones there too
…drop routing keys The extra_body merge stays in the Converse transform, after the handler has read stream, the AWS keys, endpoint and region from the top level, so extra_body can no longer change how LiteLLM sends the call. The Converse branch in completion() removes the deployment's additional_drop_params keys from extra_body before every attempt, the native output retry included, and the transform also removes model. Strict tools inside extra_body get the retry without strict, and tool calls written as text are parsed against the extra_body tools. Adds regression tests for each.
…tier, and reject malformed tools and config blocks
| **_with_the_response_format_tool(without_extra_body, sent_fields.get("tools")), | ||
| } | ||
| if "output_config" not in fields: | ||
| return {**without_extra_body, **fields} |
There was a problem hiding this comment.
Medium: Output-token overrides bypass admission limits
A request with max_tokens=32, extra_body={"maxTokens":8192} is accounted for as 32 output tokens by the proxy's _get_explicit_output_cap and router's _otpm_reservation, but this merge replaces the mapped cap and sends inferenceConfig.maxTokens=8192, allowing concurrent calls to overshoot configured TPM/OTPM limits before usage reconciliation. Resolve the effective Converse output limit before admission checks, and clamp or reject overrides of caps injected by the limiter.
|
Closed to free an open-PR slot. Branch kept. Reopen with |
Sending
extra_bodyto an OpenAI model on Bedrock Converse failed every time with Bedrock'sUnknown parameter: 'extra_body'400, with or withoutdrop_params. LiteLLM put the wholeextra_bodyobject into the Bedrock request as one field instead of sending the fields inside itNow the fields inside
extra_bodyare added to the Bedrock request, soinstructionsandprevious_response_idreach the model from a request, a stream, a deployment config or /v1/messages. Anextra_bodythat isn't a JSON object is dropped underdrop_paramsand answers a 400 without itOriginal
TLDR
Problem this solves:
extra_bodydrop_paramsdoes not help, the 400 comes from BedrockHow it solves it:
extra_bodyare added to the Bedrock requestextra_bodydrops underdrop_params, else 400Decisions and alternatives
extra_bodyunderdrop_paramswas the other option, but Bedrock accepts these fields once they are sent on their own (a direct Converse call withinstructionsanswers 200 in French), so dropping them would throw away what the caller asked forextra_bodyfield wins over a top-level field with the same name. This matches the OpenAI SDK and how LiteLLM already treatsextra_bodyfor providers that use its shared HTTP handlerextra_bodythat is not a JSON object follows thedrop_paramsconvention. It is dropped whendrop_paramsis on and answers a 400 that names the problem when it is offextra_bodyfields are merged in once, in the Converse transform after LiteLLM has read its own keys and before the message checks run, so atoolsorguardrailConfiginside it counts the same as a top-level one. A tool follow-up keeps its tool blocks, and the latest user message is marked as the guarded text and keeps its cache points under the same rule a top-levelguardrailConfiggets. Strict tools insideextra_bodyget the same retry withoutstrict, a tool call the model writes as text is matched against theextra_bodytools, and a native output retry sends the same filteredextra_bodyagain. Anoutput_configinside it replaces the onereasoning_effortset and gets the same effort cap. The merge builds a new dict, so the caller's params never keep the fields or the internal markerconverse_likeroute is unchanged. It already mergesextra_bodyat the top level through the shared HTTP handlerextra_bodyfields join the params after LiteLLM maps the OpenAI ones, so they skip that mapping anddrop_params. Anextra_bodytool_choice: "required"goes to Bedrock as written and gets Bedrock's own 400, while a top-level one becomes{"any": {}}. Runningextra_bodythrough the OpenAI mapping was the other option, but the shared HTTP handler addsextra_bodyafter the transform for every other provider, and the OpenAI SDK sends it as raw body fields, so OpenAI params belong at the top levelmodeland the keys a deployment lists inadditional_drop_paramsare removed fromextra_body, the same way the OpenAI-compatible path removes them. Sending them on was the other option, butadditional_drop_paramsis how an admin blocks a field, and Bedrock rejects amodelfield in the requestextra_bodycannot change how LiteLLM itself handles the call. Keys LiteLLM reads before the transform, such asstream, come only from the top level, so the same keys insideextra_bodygo to Bedrock as request fields, and Bedrock answers its own 400 when one conflicts with a field LiteLLM set, asstreamdoes. Lettingextra_bodyset them was the other option, but then a body field could switch a call to streaming or change where and how LiteLLM sends ittoolsfield or a config block such asguardrailConfigorperformanceConfigof the wrong type answers a 400 that names the field, even underdrop_params, the same as at the top level. Dropping it as decision 4 does was the other option, but the call would then run and bill without the tools or guardrail it asked forextra_body.toolskeeps the JSON tool LiteLLM adds forresponse_format, as a top-leveltoolsdoes. Replacing it was the other option, but then Llama answers with a tool call instead of JSONUser Flow
Before: a developer calls an OpenAI model on Bedrock with tools, reasoning and
extra_body, and every call failstools,"reasoning_effort": "low"and"extra_body": {"instructions": "Answer in French."}Unknown parameter: 'extra_body'with or withoutdrop_params, and so do streaming, a configextra_body, /v1/messages and a stringextra_bodyAfter: the same request answers 200 and the model follows the instructions
instructionsreached the model, and so do streaming, the configextra_bodyand /v1/messagesextra_bodyanswers 200 withdrop_paramsand a 400extra_body must be a JSON object, got strwithout itPre-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
Each leg runs two proxies with
--num_workers 2sharing one Redis and Postgres, and cases alternate between them. Before is main at the merge base 757041a, after is this branch at d9c550c. Every call hits real us-east-1 Bedrock, and tools plusreasoning_effortkeep gpt-6.2-sol on Converseconfig.yaml
jq filters
extra_bodyinstructions, withdrop_paramsextra_bodydrop_paramsextra_bodyinstructions(control)extra_bodyprevious_response_idextra_bodyextra_bodystore: nullextra_bodyextra_bodyinstructionsextra_bodyextra_bodyextra_bodyextra_bodyinstructionsextra_bodyextra_body, withdrop_paramsextra_bodyextra_body, withoutdrop_paramsextra_bodytoolsonly inextra_bodyreasoning_effortplusextra_bodyeffortstore: trueinadditional_drop_paramsextra_bodyextra_bodywith amodelfieldextra_bodyextra_bodystream: true, not streamingstreamconflictsextra_bodystream: falsestreamconflictsextra_bodyextra_bodyignoredextra_bodytools: {}, withdrop_paramsextra_bodyignoredtoolsmust be a listextra_bodyperformanceConfigextra_bodyignoredextra_bodytoolsextra_bodykeytools(control)extra_bodyFrench, firstextra_bodyextra_bodyextra_bodyextra_bodyserviceTierpriority, billedinclude_usagepriorityAfter (d9c550c)
extra_bodyinstructions, withdrop_paramsMistral, streaming,
extra_bodyserviceTierpriority, billedStream, then read the spend row
Before, the same stream billed 0.0000125, the standard rate, because Mistral ignored
extra_bodyat baseSame, with
include_usageEvery chunk the client gets
Before, the same four chunks came back and the usage chunk had no
service_tierBefore (757041a)
extra_bodyinstructions, withdrop_paramsSend the request
Every other case is in the gist, before and after
/live-pr-risk (d6a0835)
Base and head ran 127 cases on real Bedrock across six model families. Four paths that worked at base broke at d6a0835, and all four are fixed. At 0af8eaf, 7 streamed cases on five providers billed at the base rate, except the
extra_bodyserviceTierone, which now bills at priority. Main has since shipped its own cache and tier fixes, which this branch takes, and those cases pass at d9c550cBreaking, backward incompatible, regression risk, dependency graph, not verified
Breaking
extra_bodyshaped. After one call withextra_bodyinstructions"Answer in French.", head served that French reply from cache to the same request withoutextra_body, where base answered it in English. The cache key leaves outextra_body, which did no harm while Converse ignored it or failed. Fixed on main by fix(caching): key the response cache on extra_body by default #53898, which this branch now takesextra_body.serviceTierpriority goes to Bedrock at priority but is billed at the standard rate (Mistral 5.9e-05 where priority is about 1.03e-04). ConverseStream reports the served tier only in its lastmetadataevent, which LiteLLM dropped. Without streaming it bills correctly. Fixed on main by fix(bedrock): bill ConverseStream at the served tier #52565, which this branch now takesextra_body.toolssuch as{}orfalsegoes out with no tools, so Bedrock answers 200 and bills. Then the response parsing added in d6a0835 rejects it, and the client gets a 500 with spend 0 recorded. Mistral and Qwen3 answered 200 at base. A string answers 400 with a Python traceback in the message. Fixed in 7323aeaextra_body.performanceConfigorguardrailConfiganswers 500 before any Bedrock call, where Mistral answered 200 at base. The same string at the top level already answers 500 on both trees. Fixed in 7323aeaBackward incompatible
drop_params, a non-objectextra_bodyanswers 400 before any Bedrock call. Mistral ignored it at base and answered 200. This is decision 4extra_bodyat base now get Bedrock's 400 for a field it rejects, such asstreamon Qwen3. This is decisions 3 and 9extra_bodyfields reach Bedrock underdrop_paramsand get its 400, the same as an unknown top-level field. This is decision 3extra_bodyfields used to be thrown away and now take effect. They win over top-level ones (temperature 0.1 over 0.9), and a deploymentextra_bodyis now sent. This is decision 2extra_bodyfields skip the OpenAI param mapping, sotop_pgoes toadditionalModelRequestFields, and a temperature on Sonnet 5.5 with reasoning gets Bedrock's 400, as it did at base. This is decision 7extra_body.guardrailConfig: nullremoves the deployment guardrail while the message still goes out as guarded content, so Bedrock answers 400 on Claude and Mistral, which answered 200 at base. A top-levelnullkeeps the deployment value. It fails closed. This is decisions 2 and 3test_internal_params_never_reach_provider_bodyintests/integration/providers/test_internal_params_wire.pyfails its 4 Converse cases on head and passes on base, because it still reads the custom key underadditionalModelRequestFields.extra_body. This is decision 1, and the test needs the flat path in this PR before CircleCI on main runs it. Fixed in 7323aeaRegression risk
The buffered stream fallback was not triggered, since it needs a principal that is denied streaming. It cleans
extra_bodythe same way as the native output and strict tools fallbacks, which replayed correctly live. Withresponse_formatplusextra_body.tools, the JSON tool is replaced, so Llama returns a tool call instead of JSON and Nova gets a 400. Neither worked at base, and since 7323aeaextra_body.toolskeeps the JSON tool as a top-leveltoolsdoesDependency graph
extra_bodyadditional_drop_paramsconverse_like, pass-throughThe Bedrock unit tests and 62 other unit files that name Bedrock passed on the tip. Every integration group passed except the stale Converse test in Backward incompatible 7 and 4 load flakes, which passed on rerun on both trees
Since d6a0835
Both trees ran on 2 proxies with 2 workers each, sharing Redis and Postgres. Commands and output are in risk_before_adaa460566.md and risk_after_0af8eaf258.md
service_tierpriorityextra_bodypriorityTwo head streams wrote fewer output tokens. Every rate matches base except the last row
Not verified
The buffered stream fallback, the
converse_likeroute, Bedrock pass-through, batch files and count_tokens. Nestedadditional_drop_paramspaths and the router replacing a deploymentextra_bodywith the request's were traced onlyType
🐛 Bug Fix
Caveats (if any)
Low
extra_bodymaxTokensoverridesmax_tokens, asextra_bodydoes for OpenAI at baseextra_bodyfields still get Bedrock's own 400 underdrop_params(decision 3)extra_bodyfields to Bedrock (decisions 3, 4 and 9)converse_like, batch or count_tokensFinal Attestation