Repository navigation
fix(router): let an exact base_model widen a deployment's context window - #46197
Conversation
Merging this PR will not alter performance
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… provider Extends the Bedrock-only check to every non-Azure provider and only uses the base_model when it has its own exact cost-map entry, so an unmapped or wildcard base_model falls back to the route id instead of raising in the router.
|
|
|
Pushed a commit that extends the base_model check to every non-Azure provider and keeps the route's limits when base_model is unmapped |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Checks and execution details
View review · Reviewed |
|
bugbot run |
…model_capacity_r2
…t window A base_model used as a pricing stand-in with a smaller window no longer narrows the route's limit, and a route with no window never takes one from base_model
|
Automatic reviews are disabled for this repository. |
…get_router_model_info
|
@litereview code-review |
|
bugbot run |
charan-rathore
left a comment
There was a problem hiding this comment.
Verified locally on current main. The new capacity tests fail without the router change (8 failed, 27 passed) and the whole test_router_model_cost_isolation.py file passes with it (151 passed). The behavior matches the PR description: an exact base_model cost-map entry can raise the route's input window, never lower it, and wildcard or generalized entries are ignored. The merge order in get_router_model_info keeps user-supplied model_info and discovered info above the widened value, so explicit config still wins. The coverage-list addition documents the two new helpers as covered by those tests. LGTM.
…model A stand-in base_model for a different, larger model widened a smaller deployment's window, so pre-call checks sent it prompts the provider rejects with 400. The window now widens only when model_info.base_model names the same provider model id as the route, which is also the field /model/info reads.
|
@litereview code-review |
…ixes and @ qualifiers
|
@litereview code-review |
|
bugbot run |
|
@litereview code-review |
|
bugbot run |
… responses, and complexity escalation
|
bugbot run |
|
@litereview code-review |
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 d0b5938. Configure here.
mateo-berri
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the contribution!
TLDR
Problem this solves:
base_modelwindow/model/infoalready shows that larger window, so the two disagreeHow it solves it:
base_modelinmodel_infoorlitellm_paramswith an exact cost-map row widens the input windowglobal.and a base's@...suffix still matchmax_input_tokenswinsIntentional product change: a non-Azure same-model
base_modelwith a larger window now sets the routing windowUser Flow
Before: the router refuses a prompt that fits the window
/model/infoshowsbedrock/converse/moonshotai.kimi-k2.5withmodel_info.base_model: bedrock/us-east-1/moonshotai.kimi-k2.5andenable_pre_call_checks: truemax_input_tokens: 262144for itContextWindowExceededError ... Max Input Tokens=256000without calling BedrockAfter: the same prompt reaches Bedrock and comes back with a normal answer
bedrock/converse/moonshotai.kimi-k2.5withmodel_info.base_model: bedrock/us-east-1/moonshotai.kimi-k2.5andenable_pre_call_checks: truemax_input_tokens: 262144for itLinear ticket
Resolves LIT-9605
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 moreThe 43 tests cover Bedrock, Bedrock Mantle, and OpenAI with
base_modelin either place, both, or neither, explicit limits, many base shapes, andglobal.routes. Main fails 11 of them and 5 of the 10 new integration cellsDesign choice: widening only
max_input_tokenskeepsbase_modelpricing stand-ins working, where a whole model-info swap would break them with 400s. The same-model check keeps a stand-in for a bigger model from admitting prompts the deployment cannot take. Complexity routing and context compaction see the same windowBase source decision:
model_info.base_modelwins, thenlitellm_params.base_model, the router's existing order. Reading onlymodel_infowould keep the ticket'slitellm_paramssetup on the 400Lookup decision: the base row is looked up as written, like
/model/infodoes. Adding the route's provider would make a baremoonshotai.kimi-k2.5(256,000) readbedrock/moonshotai.kimi-k2.5(262,144)Same-model decision: an id is its last
/segment minus Bedrock region and routing prefixes, and a base may add an@...suffix. Prefix matching would letX-extendedcount asX, and dropping@on both sides would mergeX@firstandX@secondDelays 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
Last updated: d0b5938. QA and /live-pr-risk ran on f925647, the last commit with a product diff
Both legs ran on real Bedrock in us-east-1, each on its own commit and database. The served cost map adds three
@global:us-east-1base rows and lowersglobal.anthropic.claude-sonnet-4-6to 200,000. The main prompt is 258,421 tokensProxy config and payload generator
The cost map served through
LITELLM_MODEL_COST_MAP_URLis the bundled one plusbedrock/anthropic.claude-sonnet-4-5-20250929-v1:0@global:us-east-1andbedrock/anthropic.claude-sonnet-4-6@global:us-east-1at 1,000,000 andbedrock/moonshotai.kimi-k2.5@global:us-east-1at 262,144, withglobal.anthropic.claude-sonnet-4-6lowered to 200,000. Bundled windows are 256,000 formoonshotai.kimi-k2.5, 262,144 forbedrock/us-east-1/moonshotai.kimi-k2.5, 200,000 forglobal.anthropic.claude-sonnet-4-5-20250929-v1:0, 8,192 formeta.llama3-8b-instruct-v1:0, and 128,000 formeta.llama3-1-8b-instruct-v1:0.$PORT,$LITELLM_MASTER_KEY, and$Dare the port, master key, and payload directoryglobal.route,@base@baseglobal.+@, Sonnet 4.6Before (1938f53)
Cases 1 to 12
Case 1, GET /model/info
Run
Observed
Case 2, smaller base
Run
Observed
Case 3, unmapped base
Run
Observed
Case 4, POST /v1/messages
Run
Observed
Case 5, POST /v1/chat/completions
Run
Observed
Case 6, POST /v1/responses
Run
Observed
Case 7, base in litellm_params
Run
Observed
Case 8, stand-in base
Run
Observed
Case 9,
global.route,@baseRun
Observed
Case 10,
@baseRun
Observed
Case 11,
global.route,@base, Sonnet 4.6Run
Observed
Case 12, bare base
Run
Observed
After (f925647)
Case 4, POST /v1/messages
Run
Observed
The other cases
Case 1, GET /model/info
Run
Observed
Case 2, smaller base
Run
Observed
Case 3, unmapped base
Run
Observed
Case 5, POST /v1/chat/completions
Run
Observed
Case 6, POST /v1/responses
Run
Observed
Case 7, base in litellm_params
Run
Observed
Case 8, stand-in base
Run
Observed
Case 9,
global.route,@baseRun
Observed
Case 10,
@baseRun
Observed
Case 11,
global.route,@base, Sonnet 4.6Run
Observed
Case 12, bare base
Run
Observed
Notes
/model/infoagrees/audit at d0b5938
Three rigs that share nothing ran on
mateo-claude-dev, each with its own Postgres, Redis, scripted upstream, and two-worker proxy. Base is 1938f53, and head and controls are d0b5938. The cells are intests/integration/routing/test_base_model_context_window_owned_proxy.py. That file boots its own proxy withenable_pre_call_checks: true, a scripted Bedrock Converse upstream, and the bundled cost map. Its prompts are 258,433 router tokens, which is between Kimi K2.5's route row (256,000) and itsbedrock/us-east-1/row (262,144), and 246,093 tokens, which is between those rows times the 0.95 escalation buffer. Every cell checks the status and the upstream calls that carry its markerlitellm_paramsBoth head runs used seed 4106601 and order seed 7 and collected the same 10 cells. The controls lane ran 37 existing pre-call check and context window fallback cells (
test_pdf_document_pre_call_checks_owned_proxy.py,test_inferenceapis_context_window_fallbacks_wire.py,test_bedrock_mantle_context_overflow_fallbacks_wire.py) on the head, and all 37 pass. The /live-pr-risk legacy lanes at f925647 pass 167 of 167 on both legsUnit evidence is
tests/unit/test_router_model_cost_isolation.py, 159 pass at d0b5938. It covers themodel_infooverlitellm_paramsorder, never narrowing, a route with no window, an unmapped route, and the base id shapesNot driven, with reasons: streaming runs the same pre-dispatch check, DB-created deployments reach the router as the same dict,
/model/infoand spend code did not change and matched live, compaction reads the value the escalation cell checks, and chaos adds nothing because the change is a stateless per-request lookup/live-pr-risk at f925647
Verdict: no break with the cost map as shipped, one break when a same-model base row overstates its window (the Medium caveat), and one routing change the PR intends. Every scenario ran on both legs against real Bedrock in us-east-1, same config, same order, with a 214,339-token prompt (
chat_215k.json, 13,500 lines of the case 1 generator)Breaking
bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0@global:us-east-11,000,000, which this account cannot use. Groupgrp-overstatedholds that Sonnet 4.5 deployment and a plainbedrock/converse/moonshotai.kimi-k2.5(256,000). SixPOST /v1/chat/completionscalls returned 200 six times fromgrp-kimi-fitson main, and 400 five times on the tip (ContextWindowExceededError ... Input is too long for requested model ... No fallback was attempted), one 200 fromgrp-kimi-fits. Edge:_pre_call_checksnow keeps the Sonnet deployment, andshould_retry_this_errornever retries a 400. Not fixed in this PR. It needs a wrong cost-map row, and the widened rows checked against Bedrock are right (Kimi K2.5 took 258,421 tokens in case 4, and Qwen3 Coder Next and Qwen3 Next 80B both answer "maximum context length is 262144 tokens"). The follow-up is filed. No one has approved shipping it yet, so the reviewer's approval of this PR is that decisionBackward incompatible
base_modelnow also sets the router's input window when it names the same model, where it was a pricing and/model/infokey before. The complexity router follows it. Routercr-escalation(SIMPLEsonnet-4-6-global-at-qualified-basewith its route row at 200,000, COMPLEXkimi-k2-5-plain,enable_context_window_escalation: true) answered 200 on both legs, from tier COMPLEX on Kimi at $0.128 on main and from tier SIMPLE on Sonnet 4.6 at $0.723 on the tip, since SIMPLE's window is now 1,000,000. This is the intended effect, and Sonnet 4.6 really holds the prompt. Shipping it is the reviewer's call with this PRRegression risk
context_compaction.py_budget), so a widened deployment compacts later. Not driven, since it needs a complexity router with a native compactor model and a 250,000-token conversation with closed older turns. Its window input is the sameget_router_model_infovalue the escalation run above showed changingDependency graph
_pre_call_checkswindow filtercontext_window_fallbackson Bedrock 400_pre_call_checks_need_token_count_increment_deployment_usage_group_output_ceiling/model/infoctx-overstated(the same Sonnet 4.5 deployment alone, withcontext_window_fallbackstokimi-k2-5-plain) returned 200 from Kimi withx-litellm-attempted-fallbacks: 1on both legs. Main fell back on the router's own check and the tip on Bedrock's 400, which maps toContextWindowExceededErrorBadRequestErroron both legs, socontext_window_fallbacksmiss it. This is older than the PR and is filed separatelyNot verified
Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
/model/infostill differs for smaller, other-model, andlitellm_paramsbases, as on mainbase_modela pricing key only, until the releaseFinal Attestation