Skip to content

fix(bedrock_mantle): correct grok-4.3 and gemma-4 token limits - #36385

Open
xyos wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
xyos:fix/bedrock-mantle-grok-gemma-context-windows
Open

fix(bedrock_mantle): correct grok-4.3 and gemma-4 token limits#36385
xyos wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
xyos:fix/bedrock-mantle-grok-gemma-context-windows

Conversation

@xyos

@xyos xyos commented Aug 10, 2026

Copy link
Copy Markdown

Title

fix(bedrock_mantle): correct grok-4.3 and gemma-4 token limits

Relevant issues

None filed — found while auditing bedrock_mantle metadata against the live endpoint. Same class of issue as #36299 (GPT-5.6 context window), different models.

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory
  • I have added a screenshot/output of my test passing (below)
  • Keep scope isolated

Type

🐛 Bug Fix

Changes

Four bedrock_mantle entries advertise token limits that don't match what the service enforces:

model field current actual
xai.grok-4.3 input 131072 1048576
xai.grok-4.3 output 16384 1048576
google.gemma-4-31b input 256000 262144
google.gemma-4-26b-a4b input 256000 262144
google.gemma-4-e2b input 128000 131072

xai.grok-4.3 is the significant one — the input limit is understated 8x. As with #36299, the non-Bedrock counterpart already carries the larger value (xai/grok-4.3 reads 1000000), which is what suggested these were stale rather than deliberate.

Understated limits cause premature context-window errors and early auto-compaction, and clamp max_tokens far below what the model accepts.

Verification (live endpoint, bedrock-mantle us-east-2)

Input — the service reports its own cap:

xai.grok-4.3           -> prompt tokens (1300031) exceed customer model maximum (1048576)
google.gemma-4-31b     -> prompt tokens (1300034) exceed customer model maximum (262144)
google.gemma-4-26b-a4b -> prompt tokens (1300034) exceed customer model maximum (262144)
google.gemma-4-e2b     -> prompt tokens (1300030) exceed customer model maximum (131072)

A real request with 394,937 prompt tokens — 3x the currently advertised max — completed successfully on xai.grok-4.3 and correctly returned a fact planted at 85% depth, so the window is usable rather than merely accepted:

prompt_tokens : 394,937
finish_reason : stop
content       : copper-meridian-19
needle found  : True

Output — same caps apply, verified at the boundary:

xai.grok-4.3  max_tokens=1048576 -> accepted
xai.grok-4.3  max_tokens=1048577 -> 'max_tokens' (1048577) exceeds model maximum (1048576)
gemma-4-31b   max_tokens=300000  -> 'max_tokens' (300000) exceeds model maximum (262144)
gemma-4-e2b   max_tokens=140000  -> 'max_tokens' (140000) exceeds model maximum (131072)

The gemma-4 entries already had max_output_tokens == max_input_tokens, so those move together.

Left alone deliberately

Tests

Added test_context_windows_match_bedrock_limits and updated the existing test_gemma_4_bedrock_mantle_model_metadata parametrization, which pinned the old values.

$ pytest tests/test_litellm/llms/bedrock_mantle/ -q
167 passed in 4.40s

$ pytest tests/test_litellm/test_model_prices_schema.py \
         tests/test_litellm/litellm_core_utils/test_get_model_cost_map.py \
         tests/test_litellm/test_gpt_5_4_model_metadata.py -q
88 passed in 1.46s

Reverting only the JSON changes fails 7 tests, confirming the coverage is meaningful:

$ git stash -- model_prices_and_context_window.json ...backup.json
$ pytest tests/test_litellm/llms/bedrock_mantle/ -q
7 failed, 160 passed

ruff and black clean on the touched file.

Note on ci_cd/check_files_match.py

Both JSON files are updated identically. That check already fails on a clean litellm_internal_staging checkout — the backup has unrelated drift (zai/glm-5.1, openrouter/z-ai/glm-5.1, darkbloom/*). I kept this diff to just these four entries rather than absorbing that; happy to include the full sync if you'd prefer.

@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR corrects Bedrock Mantle context and output token metadata for Grok 4.3 and three Gemma 4 models, updating both runtime metadata copies and their local tests.

  • Raises Grok 4.3 input, output, and legacy token limits to 1,048,576.
  • Aligns Gemma 4 limits with their binary boundary values.
  • Adds assertions covering the revised input and output limits.

Confidence Score: 4/5

The PR appears safe to merge after the non-blocking source-comment convention issue is cleaned up.

The changed metadata is synchronized across both runtime sources and is covered by hermetic assertions; the only accepted concern is the newly added test docstring.

Files Needing Attention: tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py

Important Files Changed

Filename Overview
model_prices_and_context_window.json Updates the canonical Bedrock Mantle token-limit metadata consistently with the stated endpoint boundaries.
litellm/model_prices_and_context_window_backup.json Mirrors the four canonical metadata corrections in the bundled runtime fallback.
tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py Updates pinned Gemma limits and adds coverage for all revised entries, but introduces a docstring contrary to the repository convention.

Reviews (1): Last reviewed commit: "fix(bedrock_mantle): correct grok-4.3 an..." | Re-trigger Greptile

Comment thread tests/test_litellm/llms/bedrock_mantle/test_bedrock_mantle_transformation.py Outdated
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Four bedrock_mantle entries advertise token limits that do not match what
the service enforces. Verified by probing the live endpoint
(bedrock-mantle us-east-2) and reading the caps it reports back:

  model                  field  current    actual
  xai.grok-4.3           input   131072   1048576
  xai.grok-4.3          output    16384   1048576
  google.gemma-4-31b        in   256000    262144
  google.gemma-4-26b-a4b    in   256000    262144
  google.gemma-4-e2b        in   128000    131072

grok-4.3 is the significant one: the input limit is understated 8x. As
with the GPT-5.6 entries, the non-Bedrock counterpart already carries the
larger value (xai/grok-4.3 reads 1000000), which is what suggested the
bedrock_mantle numbers were stale rather than deliberate.

Evidence, input:
  "prompt tokens (1300031) exceed customer model maximum (1048576)"
and a real request with 394937 prompt tokens (3x the advertised max)
completed successfully on xai.grok-4.3, correctly retrieving a fact
planted at 85% depth.

Evidence, output:
  max_tokens=1048576 accepted; 1048577 -> "'max_tokens' (1048577) exceeds
  model maximum (1048576)"
The gemma-4 models behave the same way, so their max_output_tokens and
max_tokens move with the input value (they were already equal).

The understated values cause premature context-window errors and early
auto-compaction, and clamp max_tokens far below what the model allows.

Left alone deliberately: openai.gpt-oss-* keep 131072 (they are not
served on the Responses or /openai/v1 chat routes, so the cap could not
be probed the same way) and the openai.gpt-5.x entries, which are handled
separately.
@xyos
xyos force-pushed the fix/bedrock-mantle-grok-gemma-context-windows branch from c049253 to c8e4b28 Compare August 10, 2026 08:35
@xyos

xyos commented Aug 10, 2026

Copy link
Copy Markdown
Author

Removed the docstring — you're right, most tests in this file don't have one. Assertions and the JSON fix are unchanged.

@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing xyos:fix/bedrock-mantle-grok-gemma-context-windows (c8e4b28) with litellm_internal_staging (f6b9518)

Open in CodSpeed

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.

1 participant