Repository navigation
fix(deepseek): forward output_config.effort and thinking as sent on /v1/messages - #52196
mateo-berri merged 7 commits into
Conversation
…v1/messages (cherry picked from commit df53f7a)
An effort level DeepSeek does not accept now gets a 400 that lists the accepted levels, or is dropped under drop_params, instead of reaching DeepSeek and coming back as a 422 labeled api_error. The reasoning_effort alias is sent as output_config.effort, and the caller's output_config.effort wins when both are set. The tests carry their types and Final annotations (cherry picked from commit 72101af)
…ct bad aliases on /v1/messages Only DeepSeek models the cost map marks supports_reasoning get thinking and output_config.effort as sent. deepseek-chat, coder and v3 keep the base drop, so clients that send adaptive thinking on every request do not start billing thinking tokens there. A string reasoning_effort is checked against DeepSeek's levels even next to output_config.effort, and a non-object output_config is forwarded unchanged instead of being replaced (cherry picked from commit c19bc4a)
…asoning on /v1/messages Models the cost map lists without reasoning, such as deepseek-chat, keep the base reasoning_effort budget mapping, effort drop, and temperature drop. Models the cost map does not list yet get the forwarding path, like the current DeepSeek reasoning models. (cherry picked from commit b290be0)
…ig fields (cherry picked from commit 53f8382)
…rt and let reasoning_effort none clear thinking (cherry picked from commit e7260d5)
…soning A proxy deployment registers an unlisted model into the cost map, so the old check stripped thinking, effort and temperature from it. Check the cost map as loaded instead Adapted for lts/1.108.x: the line has no shared is_known_non_reasoning_model, so this module defines it on lookup_model_info_for_registration and the loaded catalog, and the new tests use local_model_cost_map since the line's conftest restores model_cost by reference (cherry picked from commit b9101fa)
PR overviewNo security issues were found in this pull request. Reviews
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
[Medium impact] The PR appears safe to merge, with no new actionable findings
|
| def is_known_non_reasoning_model(model: str, custom_llm_provider: str) -> bool: | ||
| info: Final = lookup_model_info_for_registration(model, custom_llm_provider) | ||
| if isinstance(info, ModelInfoLookupMiss) or info.get("supports_reasoning") is True: | ||
| return False | ||
| return info.get("supports_reasoning") is False or info["key"] in GetModelCostMap.loaded_model_cost_map() |
There was a problem hiding this comment.
Live proof misses final changes
844919ff6e78a784990802531184601dcaaf1ce1 changes model selection, not just tests. The repository requires live proxy proof at the latest product commit. Rerun and record the checks there 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!
There was a problem hiding this comment.
58d88dc8a7, where the live proof ran, already has this model selection change. 844919f only adds two test lines, so the product code matches
There was a problem hiding this comment.
Thanks—the live evidence does cover the unlisted-model behavior, so I overstated that part of my comment. However, 844919f is not test-only in this PR: it changes litellm/llms/deepseek/messages/transformation.py, including the model-selection helper, and is the latest product commit. The reported run at 58d88dc8a7 is from the source PR; under the required QA bar, proof from another PR does not satisfy proof at this PR’s latest product commit. I’m therefore keeping the request, narrowed to a live run on 844919f or a later commit.
There was a problem hiding this comment.
Reran every After leg live at 844919f on 2 workers. All ten cases and the unlisted leg match the earlier results, proof updated
There was a problem hiding this comment.
The body's After legs, unlisted-model leg included, now ran live at 844919f, this PR's latest product commit, so the narrowed request is met
1 similar comment
surlymochan
left a comment
There was a problem hiding this comment.
I reviewed this as a non-maintainer (verification only, no approval). I read the full diff and the new tests against the current HEAD.
Verified:
- The effort-forwarding matrix matches the tests:
output_config.effortis forwarded as sent and wins overreasoning_effort; an unknown effort raises a 400AnthropicErrornaming the field and the accepted levels, unlessdrop_paramsis set, in which case the unknown effort is dropped while otheroutput_configfields (e.g.format) are kept. - For models without reasoning, the base-class adaptive-effort/temperature handling still applies, and a model missing from the cost map is treated as a reasoning model (effort forwarded as sent), both covered by tests.
reasoning_effort: noneclearsthinking, whileoutput_config.effort: nonekeeps an explicitthinkingblock — the distinction is tested.
One question:
DEEPSEEK_EFFORT_LEVELSincludes"ultra"and"max"alongside the familiarnone/minimal/low/medium/high/xhigh. Areultra/maxlevels DeepSeek actually accepts on/v1/messages? If they are not, forwarding them just passes the API rejection through to the caller, so it would be good to confirm the level set against the DeepSeek docs (or note the source in a comment).
|
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 844919f. Configure here.
|
@surlymochan Yes. DeepSeek's own 422 for an unknown effort lists exactly these eight levels, and the live runs show ultra and max answering 200 |
Handwritten 1-3 sentence description
This is the lts/1.108.x copy of #51317, which merges on main first. DeepSeek V4 requests on /v1/messages now reach DeepSeek with the effort and thinking settings the caller sent, instead of a thinking budget DeepSeek ignores, so max, low and none behave like a direct DeepSeek call
Details
TLDR
Problem this solves:
/v1/messagesignores the caller's effort, so Claude Code's--effortdoes nothingnonestill thinks, andultraanswers 400How it solves it:
thinking,output_config.effortandtemperatureas sentreasoning_effortalias becomesoutput_config.effortdrop_paramsdeepseek-chatand other models the cost map lists without reasoning keep today's handlingUser Flow
Before: a developer on 1.108 using DeepSeek V4 through the proxy's Anthropic-format route gets DeepSeek's default effort whatever they ask for
"model": "deepseek-v4-pro"and"output_config": {"effort": "max"}bills 1764 input tokens, the same asnoneandminimal"effort": "none"or"reasoning_effort": "none"still opens the reply with athinkingblock"effort": "ultra", which DeepSeek accepts, gets a 400Unmapped reasoning effort: 'ultra'drop_params: true,"effort": "bogus"still gets a 400After: the same requests bill and answer like a direct DeepSeek call, while a level DeepSeek rejects stops at the gateway
maxand 1685 fornoneandminimal, the same as DeepSeek directtextblock and no thinking"effort": "ultra"gets a 200drop_params: true,"effort": "bogus"is dropped and the call answers 200. Without it, the call gets a 400 listing DeepSeek's levelsPre-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
Both proxies ran the same config against the real DeepSeek API with 2 workers each, Before at the line's tip e1476b2 and After at this branch's tip 844919f
deepseek-v4-proreasoning_effortmaxreasoning_effortnonedrop_paramsdeepseek-chateffort lowEach cell is the billed input tokens and the reply's first block. DeepSeek direct billed 1777 for max and 1685 for none and minimal, with the same first blocks as After
Setup, commands and raw output
Unlisted model on a proxy deployment (before e1476b2, after 844919f)
A deployment of a model the cost map does not list now sends the caller's thinking, effort and temperature to DeepSeek. DeepSeek answers 400 for the made-up name on both sides, so the leg reads the request body from the proxy's debug log
deepseek-unlisteddeepseek-v4-prodeepseek-chatUnlisted model leg
Claude Code on this line
claude --model deepseek-v4-pro --effort lowasked the same math question through each proxy, Before at e1476b2 and After at 844919f. Both answered, Before thinking for 8s with 648 output tokens and After for 13s with 769. DeepSeek's thinking length varies run to run, so the billed-input rows above are the steadier signal, and #51317 has the longer Claude Code comparisonBefore
After
Picks
The line imports the Anthropic messages base config from its pass-through path and keeps its own URL building and tool cleanup, so picks 1 to 3 keep those. The line has no
lookup_catalog_model_info, so pick 4 useslookup_model_info_for_registration. The line also has no sharedis_known_non_reasoning_model, so pick 7 defines it in the DeepSeek module on the same lookup and the cost map as loaded. Its two new tests uselocal_model_cost_map, since a Router registration would otherwise leak into later tests on this linetests/unit/llms/deepseekpasses with 80 tests at the line's tip and 110 at this branch's tip. The DeepSeek and Anthropic messages tests (546) and the utils tests for DeepSeek, reasoning and messages (30) pass too. The new Router test fails on the pick before the fix/gauntlet-mini's first run found that a proxy deployment of an unlisted model counted as listed without reasoning. Main had the same bug, so b9101fa fixed it there and it is picked here. A scoped second run held after one test-isolation fix
No dependency bumps
Type
🐛 Bug Fix
Caveats (if any)
Low
noneseparatelyLITELLM_RUST=1sends DeepSeek messages through the Rust config, which still reshapes effort (decision 8)deepseek-chatstill ignores effort and adaptive thinking, on purpose (decision 9)supports_reasoning: falseon one applies to bothmake checkfails on the line's own ruff import-order error inlitellm/main.py, the same at the line's tiposv-scan(not required) flags the line's lockfiles, like fix(openai): forward Responses background_options (lts/1.108.x) #53993's run, and this PR changes noneDecisions
budget_tokensis ignored. LiteLLM still checks the level against DeepSeek's list (none, minimal, low, medium, high, xhigh, ultra, max, from DeepSeek's own 422 text). An unknown level gets a 400 naming that list, or is dropped underdrop_params, which is the convention for a malformed param. The other option was letting DeepSeek answer, but the gateway relays that as a 422 labeledapi_erroranddrop_paramscould not drop it. The cost is a level list to update when DeepSeek adds one. The check runs only for the models in 9 that get effort as sentsupports_output_configon each DeepSeek entry would keep effort-only requests, but it would still stripthinking: adaptive(which DeepSeek accepts) and send adaptive requests at a level likeultraback through the budget mapping. The override instead keys off thesupports_reasoningflag that every DeepSeek reasoning entry already carries (see 9)thinkingpasses through unchanged,adaptiveincluded, because a direct call showed DeepSeek accepts{"type": "adaptive"}with or without efforttemperatureis kept for the models in 9 that get effort as sent. Anthropic rejects it under thinking, while DeepSeek accepts any value and ignores it only while thinking. Without this,noneplus a temperature would lose the temperature DeepSeek honors once thinking is offreasoning_effortalias on/v1/messagesbecomesoutput_config.effort, so it reaches DeepSeek like the native field. When both are sent the caller'soutput_config.effortwins, the same order the Anthropic config uses. The alias adds nothinkingblock, since DeepSeek turns thinking on or off from the level, and an alias ofnoneremoves athinkingblock the caller sent, since the Anthropic config's rule is thatnoneclears both. A nativeoutput_config.effortofnonesent beside athinkingblock goes as sent, since the caller set both. The other option was keeping the old budget mapping, which DeepSeek ignores. Models that keep the base handling in 9 still get the alias mapped to a thinking budget, as beforedrop_paramsdrops an unknownoutput_config.effort, a validreasoning_efforttakes its place. With none, onlyeffortleavesoutput_config. Other keys stay, and anoutput_configleft empty is removed/v1/messageson Python unless an operator setsLITELLM_RUST=1, which opts it into the Rust copy. Changing the Rust copy is its own change, made on main firstsupports_reasoning(V4 Pro and Flash,deepseek-reasoner, R1, V3.2) and models it does not list yet getthinking, effort andtemperatureas sent.deepseek-chat,deepseek-coderanddeepseek-v3keep the base handling unchanged, so a client like Claude Code that sendsthinking: adaptiveon every request does not start paying for thinking tokens on those models after an upgrade, andreasoning_effortstill turns thinking on there. A model the cost map does not list yet gets the reasoning handling, since every DeepSeek model released since V3.2 reasons and the repo's rule is that an unlisted model gets the provider's current behavior. The check reads the cost map as loaded, so a proxy deployment of an unlisted model still counts as unlisted, and an operator keeps the base handling withmodel_info.supports_reasoning: false. The other options, forwarding for every model or markingdeepseek-chatas reasoning, change billing or the chat completions path, so either can follow in its own PRreasoning_effortis checked against DeepSeek's levels even whenoutput_config.effortis also set, so a bad alias still gets the 400 it got before this PR, or is dropped underdrop_params. Anoutput_configthat is not an object goes to DeepSeek unchanged, which rejects it with a 422 as before, instead of being replaced by the alias. The 400 names the field that held the bad level,output_config.effortorreasoning_effortFinal Attestation
Bugbot summary