Skip to content

fix(proxy): accept router-wide default_litellm_params in required-param validation - #44483

Merged
yucheng-berri merged 2 commits into
mainfrom
litellm_router_default_required_params
Oct 8, 2026
Merged

yucheng-berri merged 2 commits into
mainfrom
litellm_router_default_required_params

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • The required-param check now also consults the router-wide default_litellm_params, treating None-valued defaults as absent to mirror the router's setdefault merge
  • Explicit request params, deployment-level defaults, and the missing-param 400s for genuinely absent params are unchanged
  • Router defaults are consulted only where dispatch actually applies them: user_config requests validate against their own config's defaults, and search / managed-agent / eval routes plus model-less direct dispatch keep the route-entry 400 (unit-pinned, mutation-checked)

User Flow

Before: an operator who sets a router-wide max_tokens default gets every Anthropic messages call rejected

  1. The operator sets router_settings: default_litellm_params: {max_tokens: 16} so every deployment gets a token cap without per-model config
  2. A client sends POST /v1/messages with model and messages and no max_tokens
  3. The call fails with HTTP 400 anthropic_messages: Missing required parameter: 'max_tokens'. and the provider is never called
  4. The same operator works around it by copying max_tokens into every entry of model_list

After: the same request reaches the provider with the default applied

  1. The operator sets the same router_settings: default_litellm_params: {max_tokens: 16}
  2. A client sends the same POST /v1/messages with model and messages and no max_tokens
  3. The call returns HTTP 200 and the provider receives max_tokens: 16
  4. A request with no default and no explicit param still returns the same informative 400

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally (tests/unit/proxy/test_route_llm_request.py: 128 passed; unit + e2e mirrors of the router-default acceptance, None-default edge, and duck-typed-router guard)
  • My PR passes all required CI/CD checks (103/104 pass; the one non-pass is the normally-skipping e2e-stage-mirror job)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Greptile Confidence Score of at least 4/5 (5/5 at d3e2b8a)

Screenshots / Proof of Fix

Shared setup: one config file, real litellm proxy processes launched from each commit, and a local HTTP upstream that records the exact provider-bound request (no mocks in the proxy path; loopback instead of a paid provider).

model_list:
  - model_name: edge
    litellm_params: {model: anthropic/claude-opus-5-5, api_base: http://127.0.0.1:49921, api_key: sk-loop}
  - model_name: default-rerank
    litellm_params: {model: cohere/rerank-v4.0-pro, api_base: http://127.0.0.1:49921, api_key: sk-loop}
router_settings:
  default_litellm_params:
    max_tokens: 16
    query: which document?
    documents: [router default document]
general_settings: {master_key: sk-master}

Before (984b413)

Router-wide max_tokens on /v1/messages

  1. curl -X POST :49922/v1/messages -H "Authorization: Bearer sk-master" -d '{"model":"edge","messages":[{"role":"user","content":"hello"}]}'
  2. Observed: HTTP 400 {"type":"error","error":{"type":"invalid_request_error","message":"anthropic_messages: Missing required parameter: 'max_tokens'."}}
  3. Upstream request log for this leg: zero provider calls

Router-wide documents on /rerank

  1. curl -X POST :49922/rerank -H "Authorization: Bearer sk-master" -d '{"model":"default-rerank","query":"which document?"}'
  2. Observed: HTTP 400 {"error":{"message":"/rerank: Missing required parameter: 'documents'.", ...}}
  3. Upstream request log for this leg: zero provider calls

After (d3e2b8a)

Router-wide max_tokens on /v1/messages

  1. Same curl against the fixed proxy
  2. Observed: HTTP 200 with the anthropic-shaped message body
  3. Upstream received POST /v1/messages with "max_tokens": 16 in the body — the router default was injected at dispatch
  4. Control: explicit "max_tokens": 16 in the request also returns 200; a request with no default configured and no explicit param still returns the informative 400 (unit-pinned)
  5. Repeated with --num_workers 4: 5/5 messages calls 200 and every worker's upstream call carries max_tokens: 16

Router-wide documents on /rerank

  1. Same curl against the fixed proxy
  2. Observed: HTTP 200 with the rerank result body
  3. Upstream received POST /v2/rerank with "documents": ["router default document"] and the query

Admin UI Logs page (same request, same page on both proxies; the playground itself always sends a max_tokens default, so the Logs page is where the operator sees the outcome):

What this shows: the merge-base proxy's Logs page, where the /v1/messages request relying on the router-wide max_tokens default is rejected — a Failure row with 0 tokens and no provider call:

before: base proxy logs showing the 400 failure row

What this shows: the fixed proxy's Logs page, where the identical requests now land as Success rows (msg_loop_01 for /v1/messages, rr_loop_01 for /rerank) with real token usage and cost:

after: fixed proxy logs showing the success row

Audit (d3e2b8a, full matrix)

Final gate over the tip, before leg at the merge base 984b4134be. Real claude-haiku-4-5 for every provider cell below (a disclosed scripted loopback only where the chaos step had to take the provider down on demand):

Cell Result
Before leg, router-default max_tokens on /v1/messages 400 (the bug); explicit param 200
Router-default max_tokens: 16, non-stream, real Anthropic 200, output tokens ≤ 16 (provider enforced the injected cap)
Same, streaming with the whole stream consumed 200, complete SSE stream
Sync and async httpx clients, no max_tokens 200 both, usage 14/16 output tokens
No default anywhere (sad) 400 with the same informative error
user_config with own model_list + defaults (opt-in on) 200; without own defaults
Chaos: provider killed mid 20-concurrent burst 20×500 clean errors, proxy alive; restored burst 20×200, exactly one upstream request per success
Worker kill on a 4-worker rig mid burst 8/8 served by surviving workers

Noted: the official Anthropic SDK requires max_tokens client-side, so SDK clients always send it — the router-default path serves raw-HTTP clients (curl, gateways). Full report with per-cell commands and the not-run list: audit_report_d3e2b8a68c.md in the run artifacts.

What this shows: the same Logs page animating from the before leg to the after leg as the failing request turns into a successful one:

audit flow

Type

🐛 Bug Fix

ran /live-pr-risk and found no regressions/backward incompatible risks

…am validation

The required-body-param check added in #43787 only consulted request data
and deployment-level litellm_params, so a param supplied solely by
router_settings.default_litellm_params (e.g. max_tokens for
/v1/messages, documents for /rerank) was rejected with a 400 at route
entry even though the router would have injected it during dispatch.
Consult the router-wide defaults in the same place, treating None-valued
defaults as absent to mirror the setdefault merge.
@yucheng-berri
yucheng-berri requested a review from a team October 4, 2026 07:13
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +253 to +254
if router_default_litellm_params.get(param) is None
and not any(deployment_params.get(param) is not None for deployment_params in candidate_litellm_params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Missing fields reach direct routes

When default_litellm_params supplies a missing field on a direct route, validation accepts a request that dispatch never fills. Search, eval, and managed-agent calls then fail instead of returning the missing-parameter 400.

Learn more

The route-entry validator checks for required body fields before dispatch. Router-wide defaults enter requests through _update_kwargs_with_deployment, but direct operations do not call it: SearchAPIRouter.async_search_with_fallbacks_helper, _init_managed_agents_api_endpoints, and the direct eval branch in _route_request_single_attempt forward the original arguments. The newly accepted request therefore lacks the required field when the called API processes it. Model-free vector-store operations also take a direct path in _init_vector_store_api_endpoints.

Example: Set router_settings.default_litellm_params.query to "weather" and call /v1/search/my-tool without a query. Validation passes, but the search-tool dispatcher never inserts query, so the call fails rather than sending the configured query or returning the missing-parameter 400.

Recommended fix: Only count router-wide defaults for routes and dispatch branches that actually merge them, or inject the same defaults before every affected direct call. Add regression cases for at least one direct route and one model-free route.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d3e2b8a: search/eval/managed-agent routes and model-less direct dispatch no longer consult router-wide defaults (they keep the route-entry 400), and user_config requests consult their own throwaway Router's defaults instead of the global one. Both behaviors are pinned by unit tests.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds router-wide default parameters to required-param validation.

The PR appears safe to merge based on the reviewed changes

Summary

The PR lets required-parameter validation recognize non-None router-wide defaults where dispatch applies them. The current head adds dispatch-specific guards, expands unit coverage, and adds an upstream assertion for rerank. All three previous Greptile threads are resolved

Reviews (2) · Last reviewed commit: "fix(proxy): consult only the defaults th..."

Comment thread litellm/proxy/route_llm_request.py Resolved
Comment thread litellm/proxy/route_llm_request.py Resolved
@codspeed

codspeed Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_router_default_required_params (d3e2b8a) with main (b61376a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (9a5e828) during the generation of this report, so b61376a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Review follow-up: router-wide defaults are now consulted only where
dispatch actually applies them. user_config requests dispatch on their
own throwaway Router, so they consult that config's defaults instead of
the global router's; search, managed-agent and eval routes, and
model-less direct dispatch never pass through the router's defaults
merge, so they keep the route-entry 400. Also adds rerank router-default
coverage (unit + e2e) and drops the redundant source comment.
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai please review the current head d3e2b8a — all three findings addressed: dispatch-mirroring gate for router defaults, comment removed, rerank coverage added (unit + e2e).

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 d3e2b8a. Configure here.

@yucheng-berri
yucheng-berri enabled auto-merge (squash) October 8, 2026 02:22
@yucheng-berri
yucheng-berri merged commit efe0715 into main Oct 8, 2026
107 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_router_default_required_params branch October 8, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants