fix(main): forward verbosity param to chat completion providers - #32254
Conversation
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the change is a two-line targeted addition that mirrors the already-working The fix is minimal: two lines in No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/main.py | Adds verbosity to the completion_kwargs dict in acompletion() and to the optional_param_args dict in completion() so it reaches get_optional_params(); the downstream handler and constants already supported it. |
| tests/test_litellm/test_main.py | Adds two regression tests — one sync (via return_raw_request) and one async (via respx_mock + acompletion) — that assert verbosity appears in the provider request body; both new tests and a shared mock helper are added without modifying existing tests. |
Reviews (1): Last reviewed commit: "fix(main): forward verbosity param to ch..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
46a8025
into
litellm_internal_staging
Relevant issues
Linear ticket
Resolves LIT-4124
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays 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
Ran a live proxy twice from an isolated git worktree with its own venv: once at the merge-base commit (before) and once at this PR's head (after). DB-free config with just the gpt-5.2 model entry and
master_key: sk-1234, served on a random unused port (59053), hitting the real OpenAI API with gpt-5.2, no mocks. Proxy started with.venv/bin/python litellm/proxy/proxy_cli.py --config qa_config.yaml --port 59053in both phasesBefore (commit 6cecb6e)
/utils/transform_requestshows the exact body LiteLLM would send to OpenAI;verbosityis silently dropped{ "model": "gpt-5.2", "messages": [ { "role": "user", "content": "hi" } ] }Live call with
verbosity: low{ "model": "gpt-5.2", "completion_tokens": 751, "content_chars": 3573 }Live call with
verbosity: high{ "model": "gpt-5.2", "completion_tokens": 709, "content_chars": 3345 }low vs high is 751 vs 709 completion tokens (high is even slightly shorter), confirming the param never reached OpenAI
After (commit fd2e2ee)
Same worktree and venv,
git checkout fd2e2eec70, same config and port. The transform now forwardsverbosity{ "model": "gpt-5.2", "messages": [ { "role": "user", "content": "hi" } ], "verbosity": "high" }Live call with
verbosity: low{ "model": "gpt-5.2", "completion_tokens": 627, "content_chars": 2956 }Live call with
verbosity: high{ "model": "gpt-5.2", "completion_tokens": 1451, "content_chars": 6537 }low vs high is now 627 vs 1451 completion tokens, a 2.3x divergence, matching the roughly 3x spread seen when calling OpenAI directly. Before the fix the spread was within 6%
Type
🐛 Bug Fix
Changes
verbosity("low"/"medium"/"high") passed tolitellm.completion()/acompletion(), and therefore to the proxy's/chat/completions, was silently dropped and never forwarded to the provider. A customer noticed that verbosity low vs high through the proxy produced near-identical gpt-5.2 outputs while calling OpenAI directly diverged about 3x in lengthRoot cause:
completion()acceptsverbosityas a named parameter, but theoptional_param_argsdict it passes toget_optional_params()omitted it. Because it is a named parameter it never landed in**kwargs/non_default_paramseither, soget_optional_params()(which already has averbosityparameter and correct GPT-5 handling vialitellm/llms/openai/chat/gpt_5_transformation.py) never received it. The async path had the same gap:acompletion()also omittedverbosityfrom thecompletion_kwargsit builds forcompletion()The fix adds
verbosityto both dicts, right next toreasoning_effortwhich follows the identical plumbing. Downstream behavior now matchesreasoning_effortsemantics: GPT-5 family models forward it, non-supporting models (e.g. gpt-4o) raiseUnsupportedParamsErrorunlessdrop_paramsis set, andpre_process_non_default_paramskeeps it since it is already inDEFAULT_CHAT_COMPLETION_PARAM_VALUESRegression tests in
tests/test_litellm/test_main.pyassert the provider request body containsverbosityfor both the sync (return_raw_request) and async (acompletionvia respx) paths; both fail on the base branch and pass with the fix