Repository navigation
feat(router)!: apply each deployment's reasoning_effort_levels on every provider and route - #46601
Conversation
…y provider and route A deployment's declared reasoning_effort_levels now decide the effort sent upstream on /v1/chat/completions, /v1/messages and /v1/responses for every provider. Requests round up by default, litellm.reasoning_effort_rounding and model_info.reasoning_effort_rounding switch to down, a declaration lets providers like azure_ai accept reasoning_effort, and each remap logs one INFO line with structured fields.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Merging this PR will not alter performance
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
…ed levels Cost map levels no longer round requests or force-allow reasoning_effort, so undeclared sibling deployments and catalog-only models behave as on main. A declaring deployment lets azure_ai accept any level the resolver sends, and a hosted_vllm chat thinking budget is rounded too.
|
bugbot run |
…ound native /v1/messages effort Under drop_params a level outside the deployment's reasoning_effort_levels is dropped instead of sent. Providers that take /v1/messages natively now round output_config.effort onto the deployment's declaration. The rounding setting ignores case and surrounding spaces.
|
bugbot run |
|
bugbot run |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. No correctness findings. I reviewed the full PR at Checks and execution details
The title
View review · Reviewed |
| api_base=api_base, | ||
| ) | ||
| routing_kwargs: Final = cast("Mapping[str, object]", kwargs) # cast-ok: kwargs is the untyped request dict | ||
| deployment_reasoning_effort: Final = resolve_deployment_reasoning_effort( |
There was a problem hiding this comment.
Low · hosted_vllm sends an effort from thinking after drop_params dropped it
- A
hosted_vllm/deployment declaresreasoning_effort_levels: ["none"](or[]), anddrop_paramsis on. - A caller sends
thinking: {"type": "enabled", "budget_tokens": 2048}and noreasoning_effort, which is what/v1/messagesclients such as Claude Code do. completion()turnsthinkingintomedium, andresolve_deployment_reasoning_effortdrops it because the deployment does not declaremedium. That leavesresolved_reasoning_effort = None.thinkingstill goes intoget_optional_params.HostedVLLMChatConfig.map_openai_paramsthen sees noreasoning_effort, derivesmediumfromthinkingagain, and sends it upstream. A plainreasoning_effort="medium"request to the same deployment is dropped, as the PR describes.
The smallest fix is to also strip thinking from the hosted_vllm params whenever the resolver changed or dropped the effort it derived from thinking.
Evidence
Local reproducer (respx stub of the vLLM endpoint; it checks the outbound body only, not a real upstream response):
completion(model="hosted_vllm/my-kimi", api_base=B, api_key="k", messages=[...],
thinking={"type":"enabled","budget_tokens":2048}, drop_params=True,
model_info={"id":"d1","reasoning_effort_levels":levels})Output:
['none'] medium
[] medium
['low', 'high'] high
reasoning_effort=medium, ['none'] None
litellm/main.py ~5490 passes reasoning_effort_from_thinking(thinking) into the resolver but still forwards the original thinking ("thinking": thinking in optional_param_args).
litellm/llms/hosted_vllm/chat/transformation.py ~98: thinking_effort = reasoning_effort_from_thinking(non_default_params.pop("thinking", None)); if thinking_effort is not None and "reasoning_effort" not in non_default_params: ... re-derives the dropped level.
Latest summary by code-review · View this review · Reviewed 680a4ec7ddb8
There was a problem hiding this comment.
Fixed in bc933eb. A thinking-derived effort now goes through drop_params, and thinking is no longer forwarded, so nothing reaches the engine
There was a problem hiding this comment.
Finding withdrawn
The reply is correct. In litellm/main.py, completion() now always computes thinking_effort for hosted_vllm and sends it through resolve_deployment_reasoning_effort, which applies drop_params. When thinking_effort is set, completion() forwards "thinking": None. HostedVLLMChatConfig.map_openai_params therefore never sees thinking and cannot derive the dropped level again. A local run confirms the outbound body has no reasoning_effort and no thinking for deployments declaring ["none"] or [].
Evidence
litellm/main.py ~5491-5499: thinking_effort = thinking_budget_effort(...) if reasoning_effort is None and thinking is not None and (custom_llm_provider == "hosted_vllm" or deployment_rounds_reasoning_effort(...))
litellm/main.py ~5501-5510: the resolver receives reasoning_effort if reasoning_effort is not None else thinking_effort along with the drop_params setting
litellm/main.py ~5647: "thinking": thinking if thinking_effort is None else None
litellm/llms/hosted_vllm/chat/transformation.py ~98: the code that derives an effort from thinking gets None and does nothing
Local respx run at head (outbound body only): ['none'] None False, [] None False, ['low','high'] high False
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed bc933ebf12c7 · View follow-up
…t on every provider
|
bugbot run |
|
@litereview code-review |
| api_base=api_base, | ||
| ) | ||
| routing_kwargs: Final = cast("Mapping[str, object]", kwargs) # cast-ok: kwargs is the untyped request dict | ||
| thinking_effort: Final = ( |
There was a problem hiding this comment.
Low · Chat requests to declaring Claude deployments lose thinking.display: omitted
- An
anthropic/claude-opus-5-5deployment (adaptive thinking) declaresreasoning_effort_levels: ["low", "high"]in itsmodel_info. - A caller sends a chat completion with
thinking: {"type": "enabled", "budget_tokens": 2048, "display": "omitted"}and noreasoning_effort. - Because the deployment declares levels,
completion()turnsthinkingintothinking_effort(medium, rounded up tohigh). It then forwards"thinking": None, so it throws away the caller's wholethinkingobject. AnthropicConfig.map_openai_paramssees onlyreasoning_effort=high._map_reasoning_effortbuildsthinking: {"type": "adaptive", "display": "summarized"}, so Anthropic getssummarizedinstead ofomitted, and the caller receives thinking text it asked to hide. Before this PR, and on deployments that declare nothing,translate_legacy_thinking_for_adaptive_modelkeepsdisplay.
Smallest fix: when thinking_effort comes from an adaptive Claude translation, keep the translated thinking (with its display) and replace only the effort, instead of nulling thinking. The native /v1/messages path already does this through with_adaptive_thinking_as_effort.
Evidence
Local reproducer at head bc933eb. A respx stub stands in for api.anthropic.com, and the script checks only the outbound body:
litellm.completion(model="anthropic/claude-opus-5-5", api_key="k", messages=[...], max_tokens=4096,
thinking={"type":"enabled","budget_tokens":2048,"display":"omitted"}, **({"model_info": mi} if mi else {}))Output (levels, sent thinking, sent output_config):
None {'type': 'adaptive', 'display': 'omitted'} {'effort': 'medium'}
['low', 'high'] {'type': 'adaptive', 'display': 'summarized'} {'effort': 'high'}
litellm/main.py ~5647: "thinking": thinking if thinking_effort is None else None
litellm/llms/anthropic/chat/transformation.py ~1386-1391: on adaptive models _map_reasoning_effort always returns AnthropicThinkingParam(type="adaptive", display="summarized")
litellm/llms/anthropic/common_utils.py ~947-951: translate_legacy_thinking_for_adaptive_model keeps display in ("summarized", "omitted"). Nothing calls it on this path once thinking is nulled.
Latest summary by code-review · View this review · Reviewed bc933ebf12c7
There was a problem hiding this comment.
Confirmed live, display omitted goes out as summarized. Keeping it as a Low caveat in the body, since only the returned thinking text changes
There was a problem hiding this comment.
Finding still applies
Thanks for checking this live. Your result confirms the finding: on a deployment that declares reasoning_effort_levels, a caller's thinking.display: "omitted" goes out as "summarized", and the caller gets back thinking text it asked to hide. Listing it as a known caveat in the PR description doesn't fix it, and the code at head hasn't changed. The finding stays at Low severity. The smallest fix is still to keep the translated adaptive thinking (with its display) and replace only the effort. The native /v1/messages path already does this through with_adaptive_thinking_as_effort.
Evidence
Author reply: "Confirmed live, display omitted goes out as summarized. Keeping it as a Low caveat in the body".
litellm/main.py:5647 at head bc933ebf12 still reads "thinking": thinking if thinking_effort is None else None, (thinking_effort is defined at line 5491).
litellm/llms/anthropic/chat/transformation.py:1391 still hardcodes display="summarized" in _map_reasoning_effort for adaptive models.
Reviewed bc933ebf12c7 · View follow-up
There was a problem hiding this comment.
Fixed in 92183fa. Chat now keeps the caller's thinking, display included, and replaces only the effort, on anthropic, bedrock, and azure_ai Claude
There was a problem hiding this comment.
Finding withdrawn
Thanks for the fix. I checked it at head 92183fa820 and it holds. completion() no longer sets thinking to None when it derives thinking_effort. It now passes the caller's thinking through adaptive_thinking_beside_effort, which returns the original object whenever the model takes adaptive translation. AnthropicConfig.map_openai_params then runs translate_legacy_thinking_for_adaptive_model, which keeps display, and the rounded effort lands in output_config.
A local reproducer confirms this on anthropic and azure_ai Claude. A deployment declaring ["low", "high"] now sends {'type': 'adaptive', 'display': 'omitted'} with effort: high. Before the fix it sent display: summarized. I did not run a bedrock reproducer, but bedrock goes through the same main.py change.
Evidence
litellm/main.py ~5648: "thinking": (thinking if thinking_effort is None else adaptive_thinking_beside_effort(thinking, resolved_reasoning_effort, model=model, custom_llm_provider=custom_llm_provider))
litellm/router_utils/reasoning_effort_capability.py adaptive_thinking_beside_effort: returns the caller's thinking when with_adaptive_thinking_as_effort produces output_config. It returns None only when the effort is None or none, or when the model is not adaptive.
Local reproducer (uv run, a respx stub stands in for the provider, and the script checks only the outbound body). Each call used thinking={"type":"enabled","budget_tokens":2048,"display":"omitted"}:
anthropic/claude-opus-5-5 None {'type': 'adaptive', 'display': 'omitted'} {'effort': 'medium'}
anthropic/claude-opus-5-5 {'reasoning_effort_levels': ['low', 'high']} {'type': 'adaptive', 'display': 'omitted'} {'effort': 'high'}
anthropic/claude-opus-4-7 {'reasoning_effort_levels': ['low', 'high']} {'type': 'adaptive', 'display': 'omitted'} {'effort': 'high'}
azure_ai/claude-opus-4-7 {'reasoning_effort_levels': ['low', 'high']} {'type': 'adaptive', 'display': 'omitted'} {'effort': 'high'}
Non-adaptive anthropic/claude-sonnet-4-6 with levels declared sends the original {'type':'enabled','budget_tokens':2048,'display':'omitted'}, the same as without levels, so nothing regressed there.
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed 92183fa8207f · View follow-up
|
@litereview code-review |
…ing budget on adaptive Claude Warn on a reasoning_effort_rounding value other than up or down instead of silently rounding up
|
bugbot run |
|
@litereview code-review |
…ing no ranked levels excludes A deployment declaring [] or ["none"] skipped the budget check, so adaptive Claude still sent the budget-derived output_config.effort under drop_params on chat, Bedrock Converse, and native /v1/messages. The adaptive thinking now goes out without that effort
|
@litereview code-review |
…ort_levels_every_route # Conflicts: # litellm/llms/anthropic/pass_through/messages/handler.py # litellm/main.py
|
@litereview code-review |
|
@litereview code-review |
1 similar comment
|
@litereview code-review |
Review already requestedcode-review is already reviewing |
|
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 dc0b5ec. Configure here.
…control Resolves the conflicts with #46411 and #46601. A prompt_cache_breakpoint on a tool now marks a tool boundary and is stripped from the tools affinity key like cache_control. The Claude cache planning in completion() now uses the resolved reasoning effort, thinking and output_config that the real call sends, and it moves into a helper so completion() stays under the type checker's complexity limit
|
The post-merge audit passed at this PR's merge commit. Its integration tests and one stale cell fix are in #48910 |
* test(routing): audit #46601 Adds integration cells for the falsy budget 400, the empty and none-only declarations under drop_params, Vertex AI Claude, Databricks Claude, and the Bedrock native output retry * test(routing): expect the Anthropic default max_tokens on Bedrock Invoke chat Reads the default from litellm instead of pinning 4096, which #48502 raised to 128000 * test(routing): assert whole sent bodies in the Vertex AI and Bedrock native output cells --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
Breaking change: a non-numeric or
truethinking.budget_tokensnow answers 400, or drops underdrop_params, and declaredreasoning_effort_levelsnow round on every route, so check both before upgradingTLDR
Problem this solves:
reasoning_effort_levelsonly worked on a few providers and routesreasoning_efforteven when declaredHow it solves it:
reasoning_effort, and remaps log at INFOThe 400 also covers undeclared deployments, and declared levels round up unless
reasoning_effort_roundingisdownUser Flow
Before: declared levels for Kimi K3 on Azure AI Foundry are ignored, and requests fail
reasoning_effort_levels: ["low", "high", "max", "none"]to anazure_ai/and ahosted_vllm/deployment'smodel_info"reasoning_effort": "medium"gets 400azure_ai does not support parameters: ['reasoning_effort'], and hosted_vllm sendsmedium--effort mediumanswers, but the azure_ai model gets no effort"reasoning": {"effort": "minimal"}gets 400Unsupported value: 'minimal'After: every route sends a declared level, and the proxy logs each change
highsenthighreaches the model"effort": "low"Decisions
Rounding up is the default, so a caller gets at least the level asked, or the strongest declared one
Only the deployment's own
model_infocounts, since the shared cost-map entry would round undeclared siblings.noneand unknown strings pass through, anddrop_paramsdrops undeclared levelsA declaration counts as support, so azure_ai keeps a declared
reasoning_effortunderdrop_params, which Claude Code turns on, and gpt-5 sends declared levels its row turns offA thinking budget becomes an effort on a declaring deployment, by Claude's own mapping on adaptive Claude, unless chat passes
thinkingto a provider that reads it, like Gemini. A level thatdrop_paramsdrops counts as never sent. Docs are in BerriAI/litellm-docs#2382Edge cases
An explicit
reasoning_effortoroutput_config.effortwins over a budget,defaultincluded, and goes out asreasoning_effortwhere the provider cannot readthinkingA
reasoning_summaryask keeps the rounded effort, and adaptive Claude follows the caller'sdrop_paramsA deployment declaring no levels, or only
none, also drops a budget-derived effort underdrop_params, so adaptive Claude gets adaptive thinking with no effortLinear ticket
Resolves LIT-9492
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
PASS at dc0b5ec. Declared levels now apply on every route and provider tested, and a malformed budget answers 400 instead of 500
Both legs ran 2-worker proxies on Postgres against real providers, recording what each provider got. Every case, Claude Code run and the rig are in this gist
mediumhighminimallowxhighxhighdrop_paramstrue,falseornulllow--effort mediumhigh--effort xhighhighmaxBefore (7b76b2b)
Chat, azure_ai,
mediumpython chat_client.py kimi-k3-azure-ai '{"reasoning_effort": "medium"}'After (dc0b5ec)
Chat, azure_ai,
mediumhighAll 137 cases
Each cell is what the provider received. Commands and outputs are in the gist, This PR and Main
lowlowmediumhighmediumhighhighmediumhighhighhighlowmediumhighhighmediumhighmediumhighlowhighmediumhighmediumhighmediumnonelowlowminimallowlowlowmediummediumhighmediumhighhighhighmaxlowlowmediumhighmediumlowlowxhighmediumhighminimalminimalhighhighhighhighhighhighmediumlowmediumhighmediumhighmediumhighlowlowmediumhighhighmediumhighlowmediumhighdefaultlowminimallowmediumhighmediummediummediumlowmediumlowmediumhighmediumhighmediumhighmediumhighmediumhighhighhighhighmediumhighmediumhighmediumhighlowxhighxhighhighxhighxhighmediumhighlowlowlowlowxhighxhighhighxhighxhighmediummediummediummediummediummediummediummediummediummediummediumlowlowlowlowlowlowlowlowlowlowlowClaude Code TUI, both legs
Each run starts the real Claude Code TUI with
ANTHROPIC_BASE_URLon the proxy, runsclaude --model <deployment> --effort <level>, then typesReply with the single word ok. Pane text and provider lines are in the gistazure_ai Kimi K3,
--effort mediumMain sends no effort, and this PR sends
highThis PR (dc0b5ec)
Main (7b76b2b)
Bedrock Converse Claude declaring low and high,
--effort mediumMain sends
medium, and this PR sendshighThis PR (dc0b5ec)
Main (7b76b2b)
Anthropic Claude declaring low and high,
--effort mediumMain sends
medium, and this PR sendshighThis PR (dc0b5ec)
Main (7b76b2b)
hosted_vllm Kimi K3,
--effort xhighMain sends
high, and this PR sendsmaxThis PR (dc0b5ec)
Main (7b76b2b)
Surprises
output_configalone reaches azure_ai chat unread, as on mainType
🆕 New Feature
Caveats (if any)
Medium
drop_params, on azure_ai and gpt-5azure_ai/FW-Kimi-K3deployment advertises levels it still 400s on/v1/messagesround-downLITELLM_LOG=INFOLow
HIGHgoes out as sent, as on maindefaultstill reaches an undeclared deployment as sent, as on maindrop_params, now namingreasoning_effort/v1/messages, skip declared levels, as on mainBlast radius
/live-pr-risk at dc0b5ec against 7b76b2b, with recorders in front of every provider
Every cell's command, both legs' answers, and the wire each provider got are in the gist
Breaking
None. Nothing answers differently from main beyond the approved changes below. Main's gpt-5 effort check from #43935, which merged since the last run, now lets a declared level through on Responses and on chat bridged to Responses (rk50-rk52), and a level the row allows goes out the same on both sides (rk56). The other main changes this PR crosses (the Bedrock native output retry, the native Databricks
/v1/messagesroute, and the Rust bridge catalog) behave the same on both sides except where a deployment declares levelsBackward incompatible
budget_tokensthat answered 200 on main now answers litellm's 400, or drops underdrop_params, on hosted_vllm, mistral, and on/v1/messagesto gemini, fireworks, and openrouter, and fromlitellm.adapter_completion,aadapter_completion, andRouter.aadapter_completion(J3). Approved by Mateo's drop_params ruling of 2026-10-02 and the round 2 ruling that a malformed budget answers 400 or dropsfalse,null, or empty string budget sentlowon main and now answers 400, or drops underdrop_params, on chat,/v1/messages, Responses, Bedrock Converse, and Bedrock Invoke (the proof's budget rows). Same approval/v1/messagesbridged to the Responses API on openai sentreasoning.effort: lowfor a malformed budget on main and now answers 400 or dropsreasoning. Same approvalmediumtohighin rk02, rk06, rk20, rk21, rk31, rk33, rk41, rk42), as caveat 1 says and the customer agreed on the ticketdrop_params, where main refused or dropped it (rk50-rk52). A backend that rejects it answers its own 400, as caveat 2 says and the ticket asksthinkingbudget on a provider that cannot readthinkingnow sends the effort and nothinkingwhere main answered 400, per the round 2 ruling that an explicit effort winsnone, now drops a budget-derived effort underdrop_params, so adaptive Claude gets adaptive thinking with no effort where main sentmedium(the empty-declaration rows in the proof). Same drop_params approvaldrop_paramsstill answers 400 for a thinking budget, now namingreasoning_effortinstead ofthinking. Low caveatAnthropicAdapter.translate_completion_input_paramsreadsdrop_paramsfrom the request orlitellm.drop_paramsand raises for a malformed budget without it. The other translation helpers keep dropping it by defaultRegression risk
map_openai_params(xai, azure o-series, github_copilot, volcengine, bedrock_mantle, sail) keep main's check, read in the code and live for bedrock_mantle onlyDependency graph
/v1/messagesnone-only declarationsfalseornullbudget, adaptive ClaudeNot verified
falseornullbudget on Databricks and Vertex AI Claude, which share the helper the proof's budget rows reachNo matching adapter givenon main and on this PR before the adapter runsAudit round 3 of 3 at d4cf71e against f6ae259
All 222 integration cells pass on two head runs, the base fails the 173 cells this PR changes, as predicted, and all 378 controls from main's neighboring reasoning and thinking tests pass on the head. The full matrix is in this gist. Round 3 found no open rows, and its approved behavior changes are these
budget_tokens: truethat answered 200 now answers 400 naming the budgetthinkingon a declaring azure_ai deployment sends the effort and nothinking/v1/messagestoopenaiwith a string budget answers 400 naming the budgetdefaultbeside a budget now sends adaptive thinking with no effort, and a level thatdrop_paramsdrops counts as never sentdrop_paramsoutput_config.effortbeside a budget on a declaring azure_ai or hosted_vllm deployment also goes out asreasoning_effortFinal Attestation
Bugbot summary