Repository navigation
fix(proxy): accept router-wide default_litellm_params in required-param validation - #44483
Conversation
…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.
|
bugbot run |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| 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) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
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.
|
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.
|
@greptileai please review the current head d3e2b8a — all three findings addressed: dispatch-mirroring gate for router defaults, comment removed, rerank coverage added (unit + e2e). |
|
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 d3e2b8a. Configure here.
TLDR
Problem this solves:
router_settings.default_litellm_paramswere rejected with a 400 at route entry/v1/messageswithoutmax_tokensreturnedanthropic_messages: Missing required parameter: 'max_tokens'.even though the router would have injected it during dispatch/rerankwithoutdocumentsfailed the same way; both regressed in fix(proxy): return 4xx instead of 500 for missing required params, invalid pagination and unknown ids #43787 and are unreleased (main only)How it solves it:
default_litellm_params, treatingNone-valued defaults as absent to mirror the router'ssetdefaultmergeuser_configrequests 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_tokensdefault gets every Anthropic messages call rejectedrouter_settings: default_litellm_params: {max_tokens: 16}so every deployment gets a token cap without per-model config/v1/messageswithmodelandmessagesand nomax_tokensanthropic_messages: Missing required parameter: 'max_tokens'.and the provider is never calledmax_tokensinto every entry ofmodel_listAfter: the same request reaches the provider with the default applied
router_settings: default_litellm_params: {max_tokens: 16}/v1/messageswithmodelandmessagesand nomax_tokensmax_tokens: 16Pre-Submission checklist
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)Screenshots / Proof of Fix
Shared setup: one config file, real
litellmproxy 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).Before (984b413)
Router-wide max_tokens on /v1/messages
curl -X POST :49922/v1/messages -H "Authorization: Bearer sk-master" -d '{"model":"edge","messages":[{"role":"user","content":"hello"}]}'{"type":"error","error":{"type":"invalid_request_error","message":"anthropic_messages: Missing required parameter: 'max_tokens'."}}Router-wide documents on /rerank
curl -X POST :49922/rerank -H "Authorization: Bearer sk-master" -d '{"model":"default-rerank","query":"which document?"}'{"error":{"message":"/rerank: Missing required parameter: 'documents'.", ...}}After (d3e2b8a)
Router-wide max_tokens on /v1/messages
/v1/messageswith"max_tokens": 16in the body — the router default was injected at dispatch"max_tokens": 16in the request also returns 200; a request with no default configured and no explicit param still returns the informative 400 (unit-pinned)--num_workers 4: 5/5 messages calls 200 and every worker's upstream call carriesmax_tokens: 16Router-wide documents on /rerank
/v2/rerankwith"documents": ["router default document"]and the queryAdmin 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/messagesrequest relying on the router-widemax_tokensdefault is rejected — aFailurerow with 0 tokens and no provider call:What this shows: the fixed proxy's Logs page, where the identical requests now land as
Successrows (msg_loop_01for/v1/messages,rr_loop_01for/rerank) with real token usage and cost:Audit (d3e2b8a, full matrix)
Final gate over the tip, before leg at the merge base
984b4134be. Realclaude-haiku-4-5for every provider cell below (a disclosed scripted loopback only where the chaos step had to take the provider down on demand):max_tokenson/v1/messagesmax_tokens: 16, non-stream, real Anthropicmax_tokensuser_configwith ownmodel_list+ defaults (opt-in on)Noted: the official Anthropic SDK requires
max_tokensclient-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.mdin 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:
Type
🐛 Bug Fix
ran /live-pr-risk and found no regressions/backward incompatible risks