Skip to content

fix(bedrock): match ten cost map context windows to Bedrock and map its overflow errors - #49768

Closed
mika-lt wants to merge 5 commits into
BerriAI:mainfrom
mika-lt:litellm_bedrock_kimi_k25_context_window
Closed

mika-lt wants to merge 5 commits into
BerriAI:mainfrom
mika-lt:litellm_bedrock_kimi_k25_context_window

Conversation

@mika-lt

@mika-lt mika-lt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Ten Bedrock cost map rows for eight models said 256,000 or 32,000 tokens, while Bedrock serves 262,144 or 32,768, so a proxy with pre-call checks refused prompts Bedrock takes

This widens the rows in both cost maps and turns Bedrock's overflow 400 into a context window error that says "prompt is too long", so fallbacks and Claude Code still handle it. It has one severe caveat, for older releases

/stupid: What the PR adds

/stupid: What breaks

Original

TLDR

Problem this solves:

  • Ten Bedrock rows sit below the window Bedrock serves, so long prompts get a proxy-side 400

How it solves it:

  • Widens the rows, maps Bedrock's overflow 400 to a context window error, and ties each row to its same-model rows in tests

User Flow

Before: a long prompt to Kimi K2.5 on Bedrock gets a 400 from the proxy, though Bedrock takes it

  1. The proxy admin serves bedrock/converse/moonshotai.kimi-k2.5 with enable_pre_call_checks: true
  2. A developer sends POST https://litellm-domain/v1/chat/completions with a prompt of about 257k tokens and a small max_tokens (or /v1/messages and /v1/responses)
  3. The proxy answers 400 ContextWindowExceededError ... Max Input Tokens=256000, Got=257620 and never calls Bedrock
  4. GET https://litellm-domain/model/info lists the model with max_input_tokens: 256000

After: the same request reaches Bedrock and comes back with an answer

  1. The proxy admin serves bedrock/converse/moonshotai.kimi-k2.5 with enable_pre_call_checks: true
  2. A developer sends POST https://litellm-domain/v1/chat/completions with a prompt of about 257k tokens and a small max_tokens (or /v1/messages and /v1/responses)
  3. The proxy forwards it and returns 200 with Bedrock's answer and about 257k prompt tokens in usage
  4. GET https://litellm-domain/model/info lists the model with max_input_tokens: 262144

Relevant issues

Follow-up to #46197, from a customer report (Pylon #10062)

Affected release

Regression in v1.103.7's bundled map, and on the default remote cost map since the Sep 21 Bedrock price sync (#42254 and #42279)

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review
Decisions
  1. The value is the window Bedrock enforces, 262144 (32768 for Qwen3 32B), not 256000 or 256 * 1000
    • Bedrock's own 400 for a longer prompt says "This model's maximum context length is 262144 tokens"
    • Called through the proxy, Bedrock took 257,245 input tokens on Kimi K2.5, 257,225 on Kimi K2 Thinking (Converse and Mantle), 257,029 on Qwen3 Next (both rows), Qwen3 Coder Next, Qwen3 235B and Qwen3 Coder 30B, 260,224 on Nemotron Nano 3 30B, and 32,422 on Qwen3 32B
    • Other rows for all eight models already say 262144 or 32768
    • The AWS model cards round these windows, as in "256K", which the price sync turned into 256000
  2. Only these ten rows change
    • The four plain Converse rows disagree with their own bedrock/ rows
    • Six rows name a model under another id whose other rows are wider, and each took a prompt over its old value live
    • 16 other Bedrock rows still say 256000 from the same kind of "256K" card, but have no wider same-model row to check against, so each needs its own check against Bedrock, and a follow-up ticket on our tracker lists them
    • The other mismatches go the other way, so they refuse nothing their wider rows accept and stay out
  3. Qwen3 Next 80B was 128000 before the price sync, so for that one row this is an old understatement, not a regression. It changes anyway because its bedrock/ rows say 262144
  4. max_tokens and max_output_tokens stay as they are, since nothing here showed them wrong
  5. The tests check that a row is at least as wide as the widest other row for the same model, rather than pinning 262144 or requiring exact equality
    • Pinning 262144 would pin an AWS fact the repo does not own
    • Exact equality would fail on the out-of-scope rows above, which are harmless in this direction
    • The six rows that name a model under another id are listed by hand, since no naming rule ties moonshot.kimi-k2-thinking to moonshotai.kimi-k2-thinking or bedrock_mantle/qwen.qwen3-32b to qwen.qwen3-32b-v1:0
  6. Bedrock's "This model's maximum context length is" 400 now raises a context window error
    • With the wider rows, a prompt LiteLLM counts under the window but the model counts over it now reaches Bedrock, where the old row used to refuse it first and hand it to context_window_fallbacks
    • Bedrock's 400 for it came back as a plain bad request, so the fallback never ran
    • Keeping a margin under 262144 instead would refuse prompts Bedrock accepts, which is the bug this fixes
    • With pre-call checks on, that prompt now reaches Bedrock once before the fallback runs. On Converse this added about 1 s (medians 8.0 s and 9.2 s), and on Mantle the fallback's own spread, 3.1 to 15.3 s, hid it
    • Older releases that load the cost map from GitHub get the rows without this mapping, which is the severe caveat
  7. Bedrock and Mantle overflow errors now put "prompt is too long" in front of the model's own text
  8. The match reuses the shared list of overflow phrases other providers already use, rather than one more Bedrock-only string
    • It covers every Bedrock and Mantle model, like every other provider's mapping
    • A context window error goes to generic fallbacks when no context_window_fallbacks is set. A plain 400 already did under the default fallback_on_unsupported_params, so only proxies that turned it off see new fallbacks
  9. The proof sends a small max_tokens, since Bedrock counts the requested output inside the window
    • The pre-call check counts only the prompt, for every provider, so a fitting prompt with a large max_tokens gets Bedrock's 400 after a round trip, then falls back where set
    • Counting max_tokens in that router-wide check is out of scope here
  10. fix(bedrock): reserve DeepSeek V3.2 output capacity and date GovCloud West Llama 3 #49732 applied a newer price sync rule, which sets a row to the card window minus its max output
    • Applied here it would give Kimi K2.5 246,144 or less, which refuses the customer's 257k prompts that Bedrock serves
    • This PR keeps the window Bedrock enforces on the prompt with a small output, which is what the pre-call check compares
    • Options for the severe caveat, recommended first:
      1. Ship as is. The customer's prompts work at merge, and older releases with fallbacks lose them in the band until they upgrade
      2. Ship the mapping now and widen the rows once it is in a stable release. This shrinks the affected releases but does not end it, and the customer waits that long
      3. Follow fix(bedrock): reserve DeepSeek V3.2 output capacity and date GovCloud West Llama 3 #49732's rule. Nothing breaks, but the customer's prompts stay refused
      4. Keep 256000 and have the customer set max_input_tokens. Nothing breaks, but the override reaches same-model deployments, as on main
  11. On this branch alone these overflows skipped order-based and weighted failover, and main's fix(router)!: scope context fallback precedence to the requested group #49779 now keeps both when the group has no context_window_fallbacks entry
    • Live on 2026-11-03, a Bedrock group with Mistral's Ministral 3B at order 1 and Llama 4 Scout at order 2 got a 257k-token prompt. The merge base answered 200 after one fallback, 71943a7 alone answered 400, and 71943a7 merged into main 482f3c3 answered 200 after one fallback
    • A group with a context_window_fallbacks entry sends overflow there instead of to the lower order, as fix(router)!: scope context fallback precedence to the requested group #49779 does for every provider
    • The match reaches every Bedrock model whose overflow says "This model's maximum context length is", so Llama 3.3 and Mistral raise the context window error too. gpt-oss words its overflow differently and is unchanged

Screenshots / Proof of Fix

Last updated: 71943a7. QA ran on 5fc4f7f (rows 1 to 5), 6777e82 (rows 6 to 8), and 71943a7 (rows 9 to 13). Changes since 6777e82: overflow errors now start with "prompt is too long". Proof remains valid because rows 1 to 8 never hit that error or hit it before an unchanged fallback. Verification: the exception mapping unit tests and rows 9 to 13

Each leg is a 2-worker proxy on real Bedrock in us-east-1, only the commit changing, with prompts of about 257k tokens and max_tokens 16, overflow rows on Converse and Mantle

Case Before (bad98c4) After
Kimi K2.5, three APIs 400 200
Qwen3 Coder Next, Qwen3 Next, Nemotron 400 200
Kimi K2 Thinking, Converse and Mantle 400 200
Five rows, longer prompt 400 200
Overflow, checks on, fallback 200 200
Three Qwen3 rows, Mantle 400 200
Kimi K2.5, streamed 400 200
Streamed fallback, three APIs 200 200
Overflow, checks on 400 from proxy "prompt is too long"
Overflow, checks off raw 400 "prompt is too long"
Overflow, checks off, fallback 400 200
Claude Code overflow raw API error "Prompt is too long"
Fallback time, checks on 8.0 to 9.5 s 3.1 to 15.3 s
Regression history
Checkpoint Commit Kimi chat Kimi messages Kimi responses Qwen3 Coder Next Qwen3 Next Nemotron Nano 3
Before the regression 5573265 200 200 200 200 400 200
After #42254 and #42279 b619cc2 400 400 400 400 400 400
Before the fix bad98c4 400 400 400 400 400 400
After the fix 5fc4f7f 200 200 200 200 200 200

Qwen3 Next's 400 before the regression comes from its row saying 128000 back then

Setup, with the config, the prompts, and the proxy start, is in this gist

Before (bad98c4)

Kimi K2.5 on /v1/chat/completions

  1. Run
    jq ".model=\"kimi-k2-5\"" $D/chat.json | curl -sS -w "\nHTTP %{http_code}\n" http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    {"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock/converse/moonshotai.kimi-k2.5, Max Input Tokens=256000, Got=257620\nmodel=kimi-k2-5. context_window_fallbacks=None. fallbacks=None.\n\nSet 'context_window_fallback' - https://docs.litellm.ai/docs/routing#fallbacks\n\nLiteLLM: model group 'kimi-k2-5' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
    HTTP 400
    
The other cases

Kimi K2.5 on /v1/messages

Steps
  1. Run
    jq ".model=\"kimi-k2-5\"" $D/messages.json | curl -sS http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c "{error: .error.message[0:160], type: .error.type, usage, answer: .content[0].text}"
    Output
    {"error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","type":"invalid_request_error","usage":null,"answer":null}
    

Kimi K2.5 on /v1/responses

Steps
  1. Run
    jq "{model: \"kimi-k2-5\", input: .messages[0].content, max_output_tokens: 16}" $D/chat.json | curl -sS http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c "{error: .error.message[0:160], code: .error.code, usage, answer: ([.output[]? | select(.type==\"message\") | .content[0].text][0])}"
    Output
    {"error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    

Qwen3 Coder Next, Qwen3 Next, and Nemotron Nano 3 on /v1/chat/completions

Steps
  1. Run
    for m in qwen3-coder-next qwen3-next-80b nemotron-nano-3-30b; do jq --arg m $m ".model=\$m" $D/english_chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, usage, answer: .choices[0].message.content}"; done
    Output
    {"model":"qwen3-coder-next","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"qwen3-next-80b","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"nemotron-nano-3-30b","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    

Kimi K2 Thinking on Converse and Mantle

Steps
  1. Run
    for m in kimi-k2-thinking kimi-k2-thinking-mantle; do jq --arg m $m ".model=\$m" $D/chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, prompt_tokens: .usage.prompt_tokens}"; done
    Output
    {"model":"kimi-k2-thinking","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","prompt_tokens":null}
    {"model":"kimi-k2-thinking-mantle","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","prompt_tokens":null}
    

Five rows with the longer English prompt

Steps
  1. Run
    for m in kimi-k2-thinking kimi-k2-thinking-mantle qwen3-next-80b-mantle qwen3-coder-next qwen3-next-80b; do jq --arg m $m ".model=\$m" $D/english_plus_chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, usage, answer: .choices[0].message.content}"; done
    Output
    {"model":"kimi-k2-thinking","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"kimi-k2-thinking-mantle","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"qwen3-next-80b-mantle","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"qwen3-coder-next","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    {"model":"qwen3-next-80b","error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window lar","code":"400","usage":null,"answer":null}
    

Qwen3 Coder Next over its window, without and with a fallback

Steps
  1. Run
    jq ".model=\"qwen3-coder-next\"" $D/chat.json | curl -sS -w "\nHTTP %{http_code}\n" http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    {"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock/converse/qwen.qwen3-coder-next, Max Input Tokens=256000, Got=257620\n\nLiteLLM: model group 'qwen3-coder-next' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
    HTTP 400
    
  2. Run
    jq ".model=\"qwen3-coder-next-with-fallback\"" $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: .choices[0].message.content}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"completion_tokens":4,"prompt_tokens":257253,"total_tokens":257257,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":4},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257253,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"86415."}
    
  3. Run
    jq ".model=\"qwen3-coder-next-with-fallback\"" $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: .content[0].text}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"input_tokens":257253,"output_tokens":4},"answer":"86415."}
    
  4. Run
    jq "{model: \"qwen3-coder-next-with-fallback\", input: .messages[0].content, max_output_tokens: 16}" $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: ([.output[]? | select(.type==\"message\") | .content[0].text][0])}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"input_tokens":257253,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":257253,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":257257,"cost":null},"answer":"86415."}
    

Qwen3 235B, Qwen3 Coder 30B, and Qwen3 32B on Mantle

Steps
  1. Run
    jq '.model="qwen3-235b-mantle"' $D/english_plus_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 100 Continue
    HTTP/1.1 400 Bad Request
    {"usage":null,"error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock_mantle/qwen.qwen3-235"}
    
  2. Run
    jq '.model="qwen3-coder-30b-mantle"' $D/english_plus_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 100 Continue
    HTTP/1.1 400 Bad Request
    {"usage":null,"error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock_mantle/qwen.qwen3-cod"}
    
  3. Run
    jq '.model="qwen3-32b-mantle"' $D/english_32k_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 400 Bad Request
    {"usage":null,"error":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock_mantle/qwen.qwen3-32b"}
    

Kimi K2.5 streamed on /v1/chat/completions

Steps
  1. Run
    jq '.model="kimi-k2-5" | .stream=true | .stream_options={include_usage: true}' $D/chat.json | curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -c '^data: {' sse
    grep -o '"prompt_tokens":[0-9]*' sse | tail -1
    grep -o '"error":{"message":"[^"]\{0,220\}' sse | head -1
    tail -c 300 sse
    Output
    HTTP/1.1 400 Bad Request
    0
    "error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock/converse/moonshotai.
    en call. No models have context window large enough for this call.\nModel=bedrock/converse/moonshotai.kimi-k2.5, Max Input Tokens=256000, Got=257620\n\nLiteLLM: model group 'kimi-k2-5' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}
    

Qwen3 Coder Next over its window, streamed, with a fallback

Steps
  1. Run
    jq '.model="qwen3-coder-next-with-fallback" | .stream=true' $D/chat.json > chat_req.json
    jq '.model="qwen3-coder-next-with-fallback" | .stream=true' $D/messages.json > messages_req.json
    jq '{model: "qwen3-coder-next-with-fallback", input: .messages[0].content, max_output_tokens: 16, stream: true}' $D/chat.json > responses_req.json
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @chat_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)":"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
          4 "model":"llama4-scout"
    "content":"864" "content":"15" "content":"."
    
  2. Run
    sleep 90
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @messages_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)":"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
          1 "model":"qwen3-coder-next-with-fallback"
    
  3. Run
    sleep 90
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @responses_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)":"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
         14 "model":"llama4-scout"
    "delta":"864" "delta":"15" "delta":"." "text":"86415."
    

Qwen3 Next on Mantle over its window on /v1/messages, no fallback

Steps
  1. Run
    jq '.model="qwen3-next-80b-mantle"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP" hdr
    jq -c '{type: .error.type, message: .error.message[0:260]}' body
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","message":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=bedrock_mantle/qwen.qwen3-next-80b-a3b-instruct, Max Input Tokens=256"}
    

Over the window with pre-call checks off, Converse and Mantle, without and with a fallback

Steps
  1. Run
    jq '.model="qwen3-coder-next"' $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","code":"400","message":"litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 262144 tokens. However, you requested 16 output tokens and your prompt contain"}
    
  2. Run
    jq '.model="qwen3-coder-next-with-fallback"' $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"model":null,"content":null,"usage":null,"error":"litellm.BadRequestError: BedrockException - {\"message\":\"The model returned the following errors: ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length i"}
    
  3. Run
    jq '.model="qwen3-next-80b-mantle"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","message":"litellm.BadRequestError: BedrockException - {\"error\":{\"code\":\"validation_error\",\"message\":\"ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 262144 tokens. However, you requested 16 output tokens and your prompt contains at l"}
    
  4. Run
    jq '.model="qwen3-next-80b-mantle-with-fallback"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"model":null,"text":null,"usage":null,"error":"litellm.BadRequestError: BedrockException - {\"error\":{\"code\":\"validation_error\",\"message\":\"ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 2621"}
    

Claude Code on Qwen3 32B, Converse and Mantle

Steps
  1. On Converse, start Claude Code with --model qwen3-32b-converse, paste the text, and press Enter. The pane ends with

      beside quiet river bank Summarize the text above in one sentence.
    ● API Error: 400 litellm.BadRequestError: BedrockException - {"message":"The model returned the following errors: Mantle
      streaming error for requestId c3e01154-366d-495b-9880-bd69a0e4309a: ErrorEvent { error: APIError { type:
      \"BadRequestError\", code: Some(400), message: \"This model's maximum context length is 32768 tokens. However, you
      requested 1024 output tokens and your prompt contains at least 31745 input tokens, for a total of at least 32769 tokens.
      Please reduce the length of the input prompt or the number of requested output tokens. (parameter=input_tokens,
    

    pr49768-bad98c4b02-cc-before-converse.png

  2. On Mantle, start Claude Code with --model qwen3-32b-mantle, paste the text, and press Enter. The pane ends with

      beside quiet river bank Summarize the text above in one sentence.
    ● API Error: 400 litellm.BadRequestError: BedrockException - {"error":{"code":"validation_error","message":"ErrorEvent {
      error: APIError { type: \"BadRequestError\", code: Some(400), message: \"This model's maximum context length is 32768
      tokens. However, you requested 1024 output tokens and your prompt contains at least 31745 input tokens, for a total of at
      least 32769 tokens. Please reduce the length of the input prompt or the number of requested output tokens.
      (parameter=input_tokens, value=31745)\", param: None } }","param":null,"type":"invalid_request_error"}}
    

    pr49768-bad98c4b02-cc-before-mantle.png

GET /model/info

Steps
  1. Run
    curl -sS http://localhost:$PORT/model/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -c '.data[] | {model_name, max_input_tokens: .model_info.max_input_tokens}'
    Output
    {"model_name":"kimi-k2-5","max_input_tokens":256000}
    {"model_name":"qwen3-coder-next","max_input_tokens":256000}
    {"model_name":"qwen3-next-80b","max_input_tokens":256000}
    {"model_name":"nemotron-nano-3-30b","max_input_tokens":256000}
    {"model_name":"kimi-k2-thinking","max_input_tokens":256000}
    {"model_name":"kimi-k2-thinking-mantle","max_input_tokens":256000}
    {"model_name":"qwen3-next-80b-mantle","max_input_tokens":256000}
    {"model_name":"qwen3-coder-next-with-fallback","max_input_tokens":256000}
    {"model_name":"llama4-scout","max_input_tokens":10000000}
    

After (5fc4f7f)

Kimi K2.5 on /v1/chat/completions

  1. Run
    jq ".model=\"kimi-k2-5\"" $D/chat.json | curl -sS -w "\nHTTP %{http_code}\n" http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    {"id":"chatcmpl-e602ede5-d9df-416d-8259-9e4b567ea869","created":1793677344,"model":"kimi-k2-5","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":" 345","role":"assistant"}}],"usage":{"completion_tokens":2,"prompt_tokens":257245,"total_tokens":257247,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257245,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
    HTTP 200
    
The other cases

Kimi K2.5 on /v1/messages

Steps
  1. Run
    jq ".model=\"kimi-k2-5\"" $D/messages.json | curl -sS http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c "{error: .error.message[0:160], type: .error.type, usage, answer: .content[0].text}"
    Output
    {"error":null,"type":null,"usage":{"input_tokens":257245,"output_tokens":2},"answer":" 645"}
    

Kimi K2.5 on /v1/responses

Steps
  1. Run
    jq "{model: \"kimi-k2-5\", input: .messages[0].content, max_output_tokens: 16}" $D/chat.json | curl -sS http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c "{error: .error.message[0:160], code: .error.code, usage, answer: ([.output[]? | select(.type==\"message\") | .content[0].text][0])}"
    Output
    {"error":null,"code":null,"usage":{"input_tokens":257245,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":257245,"video_tokens":null},"output_tokens":16,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":16},"total_tokens":257261,"cost":null},"answer":" I'm looking for item 12345 in this list. Let me analyze the pattern"}
    

Qwen3 Coder Next, Qwen3 Next, and Nemotron Nano 3 on /v1/chat/completions

Steps
  1. Run
    for m in qwen3-coder-next qwen3-next-80b nemotron-nano-3-30b; do jq --arg m $m ".model=\$m" $D/english_chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, usage, answer: .choices[0].message.content}"; done
    Output
    {"model":"qwen3-coder-next","error":null,"code":null,"usage":{"completion_tokens":2,"prompt_tokens":255686,"total_tokens":255688,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":255686,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"9"}
    {"model":"qwen3-next-80b","error":null,"code":null,"usage":{"completion_tokens":2,"prompt_tokens":255686,"total_tokens":255688,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":255686,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"5"}
    {"model":"nemotron-nano-3-30b","error":null,"code":null,"usage":{"completion_tokens":10,"prompt_tokens":260224,"total_tokens":260234,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":10},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":260224,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"The quick brown fox jumps over the lazy dog"}
    

Kimi K2 Thinking on Converse and Mantle

Steps
  1. Run
    for m in kimi-k2-thinking kimi-k2-thinking-mantle; do jq --arg m $m ".model=\$m" $D/chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, prompt_tokens: .usage.prompt_tokens}"; done
    Output
    {"model":"kimi-k2-thinking","error":null,"code":null,"prompt_tokens":257225}
    {"model":"kimi-k2-thinking-mantle","error":null,"code":null,"prompt_tokens":257225}
    

Five rows with the longer English prompt

Steps
  1. Run
    for m in kimi-k2-thinking kimi-k2-thinking-mantle qwen3-next-80b-mantle qwen3-coder-next qwen3-next-80b; do jq --arg m $m ".model=\$m" $D/english_plus_chat.json | curl -sS http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @- | jq -c --arg m $m "{model: \$m, error: .error.message[0:160], code: .error.code, usage, answer: .choices[0].message.content}"; done
    Output
    {"model":"kimi-k2-thinking","error":null,"code":null,"usage":{"completion_tokens":16,"prompt_tokens":251162,"total_tokens":251178,"completion_tokens_details":{"reasoning_tokens":15,"text_tokens":1},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":251162,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":""}
    {"model":"kimi-k2-thinking-mantle","error":null,"code":null,"usage":{"completion_tokens":16,"prompt_tokens":251162,"total_tokens":251178},"answer":null}
    {"model":"qwen3-next-80b-mantle","error":null,"code":null,"usage":{"completion_tokens":2,"prompt_tokens":257029,"total_tokens":257031},"answer":"8"}
    {"model":"qwen3-coder-next","error":null,"code":null,"usage":{"completion_tokens":2,"prompt_tokens":257029,"total_tokens":257031,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257029,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"9"}
    {"model":"qwen3-next-80b","error":null,"code":null,"usage":{"completion_tokens":2,"prompt_tokens":257029,"total_tokens":257031,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257029,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"7"}
    

Qwen3 Coder Next over its window with a fallback, pre-call checks on

Steps
  1. Run
    jq ".model=\"qwen3-coder-next-with-fallback\"" $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: .choices[0].message.content}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"completion_tokens":4,"prompt_tokens":257253,"total_tokens":257257,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":4},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257253,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"answer":"86415."}
    
  2. Run
    jq ".model=\"qwen3-coder-next-with-fallback\"" $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: .content[0].text}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"input_tokens":257253,"output_tokens":4},"answer":"86415."}
    
  3. Run
    jq "{model: \"qwen3-coder-next-with-fallback\", input: .messages[0].content, max_output_tokens: 16}" $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c "{model, error: .error.message[0:200], usage, answer: ([.output[]? | select(.type==\"message\") | .content[0].text][0])}" body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","error":null,"usage":{"input_tokens":257253,"input_tokens_details":{"audio_tokens":null,"cached_tokens":0,"cached_tokens_details":null,"cache_write_tokens":0,"image_tokens":null,"text_tokens":257253,"video_tokens":null},"output_tokens":4,"output_tokens_details":{"audio_tokens":null,"reasoning_tokens":0,"text_tokens":4},"total_tokens":257257,"cost":null},"answer":"86415."}
    

GET /model/info

Steps
  1. Run
    curl -sS http://localhost:$PORT/model/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -c '.data[] | {model_name, max_input_tokens: .model_info.max_input_tokens}'
    Output
    {"model_name":"kimi-k2-5","max_input_tokens":262144}
    {"model_name":"qwen3-coder-next","max_input_tokens":262144}
    {"model_name":"qwen3-next-80b","max_input_tokens":262144}
    {"model_name":"nemotron-nano-3-30b","max_input_tokens":262144}
    {"model_name":"kimi-k2-thinking","max_input_tokens":262144}
    {"model_name":"kimi-k2-thinking-mantle","max_input_tokens":262144}
    {"model_name":"qwen3-next-80b-mantle","max_input_tokens":262144}
    {"model_name":"qwen3-coder-next-with-fallback","max_input_tokens":262144}
    {"model_name":"llama4-scout","max_input_tokens":10000000}
    

After (6777e82)

The three new cases

Qwen3 235B, Qwen3 Coder 30B, and Qwen3 32B on Mantle

Steps
  1. Run
    jq '.model="qwen3-235b-mantle"' $D/english_plus_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 100 Continue
    HTTP/1.1 200 OK
    x-litellm-model-group: qwen3-235b-mantle
    x-litellm-attempted-fallbacks: 0
    {"usage":{"completion_tokens":2,"prompt_tokens":257029,"total_tokens":257031},"error":null}
    
  2. Run
    jq '.model="qwen3-coder-30b-mantle"' $D/english_plus_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 100 Continue
    HTTP/1.1 200 OK
    x-litellm-model-group: qwen3-coder-30b-mantle
    x-litellm-attempted-fallbacks: 0
    {"usage":{"completion_tokens":3,"prompt_tokens":257029,"total_tokens":257032},"error":null}
    
  3. Run
    jq '.model="qwen3-32b-mantle"' $D/english_32k_chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    jq -c '{usage, error: .error.message[0:220]}' body
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: qwen3-32b-mantle
    x-litellm-attempted-fallbacks: 0
    {"usage":{"completion_tokens":16,"prompt_tokens":32422,"total_tokens":32438},"error":null}
    

Kimi K2.5 streamed on /v1/chat/completions

Steps
  1. Run
    jq '.model="kimi-k2-5" | .stream=true | .stream_options={include_usage: true}' $D/chat.json | curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -c '^data: {' sse
    grep -o '"prompt_tokens":[0-9]*' sse | tail -1
    grep -o '"error":{"message":"[^"]\{0,220\}' sse | head -1
    tail -c 300 sse
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: kimi-k2-5
    x-litellm-attempted-fallbacks: 0
    4
    "prompt_tokens":257245
    245,"total_tokens":257247,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":2},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257245,"cache_write_tokens":0,"cache_creation_tokens":0},"cost":0.154353,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}
    data: [DONE]
    

Qwen3 Coder Next over its window, streamed, with a fallback

Steps
  1. Run
    jq '.model="qwen3-coder-next-with-fallback" | .stream=true' $D/chat.json > chat_req.json
    jq '.model="qwen3-coder-next-with-fallback" | .stream=true' $D/messages.json > messages_req.json
    jq '{model: "qwen3-coder-next-with-fallback", input: .messages[0].content, max_output_tokens: 16, stream: true}' $D/chat.json > responses_req.json
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @chat_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)": ?"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
          4 "model":"llama4-scout"
    "content":"864" "content":"15" "content":"."
    
  2. Run
    sleep 90
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @messages_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)": ?"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
          1 "model":"qwen3-coder-next-with-fallback"
    "text": "##" "text": " Step" "text": " 1: Identify" "text": " the pattern"
    
  3. Run
    sleep 90
    curl -sS -N -D hdr -o sse http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @responses_req.json
    grep -iE "^HTTP|x-litellm-attempted-fallbacks|x-litellm-model-group" hdr
    grep -o '"model":"[^"]*"' sse | sort | uniq -c | head -3
    grep -oE '"(text|delta|content)": ?"[^"]{1,40}"' sse | head -4 | tr '\n' ' '
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
         14 "model":"llama4-scout"
    "delta":"864" "delta":"15" "delta":"." "text":"86415."
    

After (71943a7)

The overflow cases and the fallback timing

Over the window with pre-call checks on, Converse and Mantle

Steps
  1. Run
    jq ".model=\"qwen3-coder-next\"" $D/chat.json | curl -sS -w "\nHTTP %{http_code}\n" http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    {"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: BedrockException: Context Window Error - prompt is too long: {\"message\":\"The model returned the following errors: ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 262144 tokens. However, you requested 16 output tokens and your prompt contains at least 2
    HTTP 400
    
  2. Run
    jq '.model="qwen3-next-80b-mantle"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","message":"litellm.ContextWindowExceededError: litellm.BadRequestError: prompt is too long: {\"error\":{\"code\":\"validation_error\",\"message\":\"ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 262144 tokens. However, you requested 16 output tokens and your prompt contains at least 262129 input tokens,
    

Over the window with pre-call checks off, Converse and Mantle, without and with a fallback

Steps
  1. Run
    jq '.model="qwen3-coder-next"' $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","code":"400","message":"litellm.ContextWindowExceededError: litellm.BadRequestError: BedrockException: Context Window Error - prompt is too long: {\"message\":\"The model returned the following errors: ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is "}
    
  2. Run
    jq '.model="qwen3-coder-next-with-fallback"' $D/chat.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","content":"86415.","usage":{"completion_tokens":4,"prompt_tokens":257253,"total_tokens":257257,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":4},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":257253,"cache_write_tokens":0,"cache_creation_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0},"error":null}
    
  3. Run
    jq '.model="qwen3-next-80b-mantle"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 400 Bad Request
    {"type":"invalid_request_error","message":"litellm.ContextWindowExceededError: litellm.BadRequestError: prompt is too long: {\"error\":{\"code\":\"validation_error\",\"message\":\"ErrorEvent { error: APIError { type: \\\"BadRequestError\\\", code: Some(400), message: \\\"This model's maximum context length is 262144 tokens. However, you requested 16 output"}
    
  4. Run
    jq '.model="qwen3-next-80b-mantle-with-fallback"' $D/messages.json | curl -sS -D hdr -o body http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-
    Output
    HTTP/1.1 200 OK
    x-litellm-model-group: llama4-scout
    x-litellm-attempted-fallbacks: 1
    {"model":"us.meta.llama4-scout-17b-instruct-v1:0","text":"86415.","usage":{"input_tokens":257253,"output_tokens":4},"error":null}
    

Fallback time with pre-call checks on, Converse and Mantle, three runs each

Steps
  1. On the base (bad98c4), run
    for i in 1 2 3; do
      echo -n "converse /v1/chat/completions run $i: "; jq '.model="qwen3-coder-next-with-fallback"' $D/chat.json | curl -sS -D hdr -o body -w "%{http_code} %{time_total}s" http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-; echo " fallbacks=$(grep -i x-litellm-attempted-fallbacks hdr | tr -d '\r' | cut -d' ' -f2)"; sleep 75
      echo -n "mantle /v1/messages run $i: "; jq '.model="qwen3-next-80b-mantle-with-fallback"' $D/messages.json | curl -sS -D hdr -o body -w "%{http_code} %{time_total}s" http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d @-; echo " fallbacks=$(grep -i x-litellm-attempted-fallbacks hdr | tr -d '\r' | cut -d' ' -f2)"; sleep 75
    done
    Output. Runs 1 and 2 ran without the pause, and the first run 3 hit Bedrock's tokens-per-minute limit on the fallback model, so it ran again with the pause
    converse /v1/chat/completions run 1: 200 9.222333s fallbacks=1
    mantle /v1/messages run 1: 200 8.253176s fallbacks=1
    converse /v1/chat/completions run 2: 200 8.034024s fallbacks=1
    mantle /v1/messages run 2: 200 9.507913s fallbacks=1
    converse /v1/chat/completions run 3: 400 7.017394s fallbacks=
    mantle /v1/messages run 3: 400 7.961143s fallbacks=
    converse /v1/chat/completions run 3: 200 8.015689s fallbacks=1
    mantle /v1/messages run 3: 200 8.145389s fallbacks=1
    
  2. On 71943a7, run the same loop
    converse /v1/chat/completions run 1: 200 9.102460s fallbacks=1
    mantle /v1/messages run 1: 200 15.347556s fallbacks=1
    converse /v1/chat/completions run 2: 200 10.164375s fallbacks=1
    mantle /v1/messages run 2: 200 4.048757s fallbacks=1
    converse /v1/chat/completions run 3: 200 9.214920s fallbacks=1
    mantle /v1/messages run 3: 200 3.144474s fallbacks=1
    

Claude Code on Qwen3 32B, Converse and Mantle

Steps
  1. On Converse, start Claude Code with --model qwen3-32b-converse, paste the text, and press Enter. The pane ends with

      beside quiet river bank Summarize the text above in one sentence.
      ⎿  Prompt is too long · this conversation is a single exchange and cannot be compacted — the request size comes mostly from system
         prompt, tool definitions, or attachments. · /clear to start fresh
    ✻ Worked for 1s · done 7:40 AM
                                                                                                                      ● high · /effort
    ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    

    pr49768-71943a78fd-cc-after-converse.png

  2. On Mantle, start Claude Code with --model qwen3-32b-mantle, paste the text, and press Enter. The pane ends with

      fresh winter snow the quick brown fox distant moumarize the text above in one sentence.
      ⎿  Prompt is too long · this conversation is a single exchange and cannot be compacted — the request size comes mostly from system
         prompt, tool definitions, or attachments. · /clear to start fresh
    ✻ Sautéed for 0s · done 7:41 AM
                                                                                                                      ● high · /effort
    ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    

    pr49768-71943a78fd-cc-after-mantle.png

Type

🐛 Bug Fix

Caveats (if any)

Severe

  • Older releases with only context_window_fallbacks lose them for these models at merge
    • They load main's cost map by default without this PR's overflow mapping, so a prompt the model counts over its window gets Bedrock's 400, not the fallback
    • Generic fallbacks still run. Upgrading or LITELLM_LOCAL_MODEL_COST_MAP=True avoids it (Decision 10)

Medium

Low
  • LiteLLM counts about 375 more Kimi K2.5 tokens than Bedrock
  • Every Bedrock overflow saying "maximum context length", Llama and Mistral included, is now a context window error, so callbacks and spend logs show that class
  • With main's fix(router)!: scope context fallback precedence to the requested group #49779, order failover still runs on that overflow, but a group with a context_window_fallbacks entry goes there first (Decision 11)
  • A deployment's max_input_tokens still reaches same-model deployments, as on main
  • A large max_tokens can still overflow at Bedrock, then falls back where set
  • When the requested output fills the window, Claude Code still says "Prompt is too long". The API message keeps the model's text, output tokens included
  • Phrase matching ignores the status code, as it did before
  • The price sync that wrote 256000 is unchanged, but the new tests block it from reverting these rows
  • codecov/patch maps coverage from the merge with main onto this branch's lines, so it can flag lines that ran. Local patch coverage is 100%

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes error classification for all Bedrock overflow responses matching shared context-window phrases (enabling fallbacks where they previously saw BadRequestError) and raises advertised input limits used by pre-call routing; older releases loading the remote cost map without this mapping remain a compatibility gap.

Overview
Fixes proxy pre-call checks refusing long prompts that Bedrock actually accepts by updating ten max_input_tokens entries in both cost maps from 256000 → 262144 (and 32000 → 32768 for Qwen3 32B Mantle) for Kimi, Qwen, Nemotron, and related Converse/Mantle rows.

Bedrock and Bedrock Mantle overflow handling now treats model text like "This model's maximum context length is…" as ContextWindowExceededError via the shared ExceptionCheckers.is_error_str_context_window_exceeded path, and prefixes prompt is too long: when missing (including Mantle validation_error bodies) so context_window_fallbacks and clients such as Claude Code recognize overflow. Messages that already contain that phrase are not duplicated.

Regression tests cover Mantle/Converse overflow mapping and assert Bedrock cost-map rows are at least as wide as sibling rows for the same model.

Reviewed by Cursor Bugbot for commit 71943a7. Bugbot is set up for automated code reviews on this repo. Configure here.

/live-pr-risk at 71943a7 found no break at merge into current main and one older-release break waiting on the severe sign-off, in this report

…input window

moonshotai.kimi-k2.5, qwen.qwen3-coder-next, qwen.qwen3-next-80b-a3b and nvidia.nemotron-nano-3-30b said 256000 while their bedrock/ and regional rows and Bedrock itself allow 262144, so router pre-call checks refused prompts Bedrock accepts. Adds a test that a bare Bedrock row is never narrower than its bedrock/ rows.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The PR changes prompt limits and overflow handling for Bedrock model requests.

The PR still needs the older-proxy rollout issue addressed and the recovery fix from main included before merging

Findings

  1. P1 Older proxies lose fallbacks ▶
  2. P1 Overflow skips working deployments ▶

Summary

This PR widens ten Bedrock input limits in both cost maps and maps more overflow errors to ContextWindowExceededError

The latest change keeps Mantle's original overflow details while adding “prompt is too long”. It also shares the prefix helper with the Bedrock path and adds a test assertion for the preserved token count

No new findings were accepted in this review

  • Bedrock model checks now use the full input windows.
  • Bedrock overflow errors now work as context-window errors.

Reviews (8) · Last reviewed commit: "fix(bedrock): keep the Mantle model's ov..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing mika-lt:litellm_bedrock_kimi_k25_context_window (71943a7) with main (ecb8ef5)

Open in CodSpeed

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ellm/litellm_core_utils/exception_mapping_utils.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…owExceededError and raise three same-model rows to 262144
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

… on a served model's Mantle overflow

Mantle's Qwen3 235B, Qwen3 Coder 30B and Qwen3 32B rows were narrower than their Converse rows, and Mantle took the longer prompts live. A Mantle overflow carrying the served model's own text now gets the same prompt is too long message as Mantle's other overflow shapes, so Claude Code compacts
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

"output_cost_per_token_flex": 4.4e-07,
"litellm_provider": "bedrock_mantle",
"max_input_tokens": 256000,
"max_input_tokens": 262144,

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.

P1 Older proxies lose fallbacks

Older proxies fetch these wider limits from main without receiving the new overflow mapping. Prompts that previously triggered context_window_fallbacks can instead reach Bedrock and return a plain 400, skipping the configured fallback

The repository requires resurfacing this caveat rather than treating its inclusion in the description as approval. Stage the remote-map rollout so older installations keep their fallback behavior

Rule Used: What: do not treat the caveats mentioned in the PR description as acceptable tradeoffs that some human has read and signed off on. Why: almost every time, the PR description is AI-generated, and in fact, many times, the PR description is very long. ... (source)

@mateo-berri mateo-berri changed the title fix(cost-map): raise four bare Bedrock Converse rows to their 262144 input window fix(bedrock): match ten cost map context windows to Bedrock and map its overflow errors Nov 3, 2026
Bedrock and Mantle overflow errors that map to ContextWindowExceededError now carry
"prompt is too long" once, so Claude Code reads them as an overflow and compacts
instead of showing a raw API error
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

or "prompt is too long" in error_str
or "prompt: length: 1.." in error_str
or "Too many input tokens" in error_str
or ExceptionCheckers.is_error_str_context_window_exceeded(error_str)

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.

P1 Overflow skips working deployments

If a group relies on order-based or weighted failover, these newly mapped ContextWindowExceededError errors skip both paths. Requests can fail instead of reaching a working deployment. Repository rules require resurfacing this caveat. Preserve recovery or move affected deployments into context_window_fallbacks

Rule Used: What: do not treat the caveats mentioned in the PR description as acceptable tradeoffs that some human has read and signed off on. Why: almost every time, the PR description is AI-generated, and in fact, many times, the PR description is very long. ... (source)

Knowledge Base Used: Fallbacks, retries, and failure handling

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!

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.

Main's #49779 keeps order and weighted failover when the group has no context_window_fallbacks entry. Merged with main, a live Bedrock order group answered 200

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

Squash merge applies this branch onto current main, which already has #49779. Merged with main, the live Bedrock order group failed over and answered 200

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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 71943a7. Configure here.

@mika-lt mika-lt closed this Nov 8, 2026
@mika-lt

mika-lt commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Closed to free an open-PR slot. Branch kept. Reopen with gh pr reopen 49768 when ready for final CI and bot reviews

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