fix(bedrock): align Claude context-window table with Anthropic docs - #24059
fix(bedrock): align Claude context-window table with Anthropic docs#24059patrick-muller wants to merge 3 commits into
Conversation
Claude 4.x models on Bedrock support a 1M-token context window via the context-1m-2025-08-07 beta header, which Hermes already injects automatically in build_anthropic_bedrock_client (agent/anthropic_adapter.py). However, BEDROCK_CONTEXT_LENGTHS in agent/bedrock_adapter.py still reported 200K for opus-4-6, sonnet-4-6, sonnet-4-5, and haiku-4-5, and had no entry at all for opus-4-7 (which falls back via substring match to the 200K opus-4 entry). This caused Hermes to display a 200K window, compress conversations earlier than necessary (compression.threshold * 200K instead of * 1M), and generally under-utilize the full 1M context users are paying for. The fix is metadata-only — the Bedrock API and beta header already support 1M end-to-end. agent/model_metadata.py's DEFAULT_CONTEXT_LENGTHS table already lists claude-opus-4-7 / -4-6 / sonnet-4-6 at 1M for the non-Bedrock paths, so this change brings the Bedrock table into alignment. Changes: - Add anthropic.claude-opus-4-7 at 1_000_000 - Bump anthropic.claude-opus-4-6 from 200_000 to 1_000_000 - Bump anthropic.claude-sonnet-4-6 from 200_000 to 1_000_000 - Bump anthropic.claude-sonnet-4-5 from 200_000 to 1_000_000 - Bump anthropic.claude-haiku-4-5 from 200_000 to 1_000_000 - Add explanatory comment pointing readers at the beta-header injection site in agent/anthropic_adapter.py
|
Supersedes #16686 — both fix BEDROCK_CONTEXT_LENGTHS for Claude 4.x to 1M, but this PR is more comprehensive (also updates sonnet-4-5 and haiku-4-5, adds opus-4-7 entry). |
…thropic docs The previous commit in this branch bumped claude-sonnet-4-5 and claude-haiku-4-5 to 1_000_000 on the assumption the context-1m-2025-08-07 beta enabled 1M on all Claude 4.x models. Verification against Anthropic's own documentation shows that is incorrect: - Claude Haiku 4.5 is a standard 200K model per https://platform.claude.com/docs/en/about-claude/models/overview (the 'Latest models comparison' table shows '200k tokens' for Haiku 4.5). - Claude Sonnet 4.5 had its 1M beta retired on April 30, 2026 per https://platform.claude.com/docs/en/release-notes/overview: 'We've retired the 1M token context window beta (context-1m-2025-08-07) for Claude Sonnet 4.5 and Claude Sonnet 4. The beta header now has no effect on these models, and requests exceeding the standard 200k-token context window return an error.' Revert both entries to 200_000. Opus 4.7, Opus 4.6, and Sonnet 4.6 remain at 1_000_000 — those three have 1M generally available with no beta header required per the same source. Also updates the header comment to cite the Anthropic models overview and the April 30 2026 release note so future readers have an upstream source of truth.
Update TestBedrockContextLength to assert the corrected values from BEDROCK_CONTEXT_LENGTHS: - test_claude_opus_4_6: 200_000 -> 1_000_000 (1M GA for Opus 4.6) - test_claude_sonnet_versioned: 200_000 -> 1_000_000 (1M GA for Sonnet 4.6) - test_inference_profile_resolves: 200_000 -> 1_000_000 (us.anthropic.claude-sonnet-4-6 resolves to Sonnet 4.6's 1M value) Also adds three new test cases that document Anthropic's published context windows explicitly and guard against future regressions: - test_claude_opus_4_7: asserts 1_000_000 and cites the models overview - test_claude_sonnet_4_5_is_200k: asserts 200_000 and cites the April 30, 2026 release note retiring the 1M beta for Sonnet 4.5 - test_claude_haiku_4_5_is_200k: asserts 200_000 for Haiku 4.5 All 178 tests in test_bedrock_adapter.py pass after the change.
|
Thanks for the spot! Quick clarification so the comparison is accurate: #16686 also adds the The actual delta vs #16686:
I've added a Prior Art section to the PR body crediting @mmcclean-aws. Happy for maintainers to take either path — close #16686 in favor of this one, or land #16686 first and let me layer the tests/doc-citations on top. Whatever's easier for review. |
|
Happy to close #16686 and use this PR as it has the tests missing from my PR |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for correcting a live Bedrock context-resolution defect. Current main still returns the stale static values from agent/bedrock_adapter.py:1300-1301 through the provider path at agent/model_metadata.py:2189-2196.
Problems
- The table remains incomplete for current 1M Bedrock models. Anthropic's current overview lists Bedrock Opus 4.8 and Sonnet 5 as 1M. With this PR, Opus 4.8 still matches the existing 200K
anthropic.claude-opus-4fallback (agent/bedrock_adapter.py:1304,:1338), while Sonnet 5 falls back to 128K (:1325). - The table update leaves the explanatory claim that Bedrock Claude is capped at 200K in
agent/model_metadata.py:2180-2184, which would no longer describe the updated behavior. - The newly added model/value assertions are catalog snapshots. The repository rubric asks for resolution invariants rather than tests that fail whenever provider metadata changes.
Suggested changes
- Include current 1M Bedrock families and test longest-match/regional-ID resolution.
- Update the stale
model_metadata.pycomment. - Keep a behavior-focused lookup invariant instead of adding per-model snapshot guards.
Automated hermes-sweeper review.
| # (no beta header required as of April 2026). Sonnet 4.5 and Sonnet 4 | ||
| # had their `context-1m-2025-08-07` beta retired on April 30, 2026, | ||
| # so they are standard 200K; Haiku 4.5 is 200K. | ||
| "anthropic.claude-opus-4-7": 1_000_000, |
There was a problem hiding this comment.
Please extend this same table update to the current 1M Bedrock families: Anthropic's current overview lists Bedrock Opus 4.8 and Sonnet 5 at 1M. Otherwise Opus 4.8 still matches the existing 200K anthropic.claude-opus-4 fallback and Sonnet 5 falls through to the 128K default.
Supersedes #16686 (now closed, not merged) — same core |
|
Merged via PR #67977 — all three of your commits were cherry-picked onto current main with your authorship preserved (rebase merge). You were the earliest submission in this cluster (May 11) and your doc citations (GA dates, the Sonnet 4.5 beta retirement) anchored the whole table. Opus 4.8 rows from a later PR (#54918) were added on top. Thanks! |
What does this PR do?
The
BEDROCK_CONTEXT_LENGTHStable inagent/bedrock_adapter.pyreportedstale values for recent Anthropic Claude models on Bedrock:
claude-opus-4-7— falls through via substring match tothe generic
claude-opus-4entry at 200K, i.e. 5x too small.claude-opus-4-6reported 200K, but is 1M generally available.claude-sonnet-4-6reported 200K, but is 1M generally available.This table feeds
get_bedrock_context_length()→get_model_context_length(),which drives the displayed context window in
/usage, the compressionthreshold (
compression.threshold * context_length), and subagentcontext budgets. A 5x-too-small value causes premature context
compression and under-utilizes the context window users are paying for.
This PR is metadata-only — no API routing, transport behavior, or
beta-header handling is changed. Claude-on-Bedrock continues to route
through
AnthropicBedrockSDK viaapi_mode: anthropic_messagesexactlyas before.
Values per Anthropic's official models comparison
Source: https://platform.claude.com/docs/en/about-claude/models/overview
(the "Latest models comparison" table, column: "Context window"):
anthropic.claude-opus-4-7anthropic.claude-opus-4-6anthropic.claude-sonnet-4-6anthropic.claude-sonnet-4-5anthropic.claude-haiku-4-5Why Sonnet 4.5 and Haiku 4.5 remain at 200K — and
claude-opus-4/claude-sonnet-4/claude-3-*also remain at 200K:Related Issue
No existing issue — discovered while running
us.anthropic.claude-opus-4-7on Bedrock and seeing a 200K window displayed instead of 1M.
Related (but distinct) bugs in the same resolution chain:
get_model_context_length()step 2context-1m-2025-08-07beta header for Anthropic Enterprise OAuth subscriptions #21557 — inverse concern: some Anthropic Enterprise OAuth accountscannot use the 1M beta
Fixes #
Prior art
A previous PR — #16686 by @mmcclean-aws (opened April 27, 2026) — had
the same core insight and the same three source lines (add
claude-opus-4-7, bumpclaude-opus-4-6andclaude-sonnet-4-6to 1M).This PR is a superset of that work:
inference-profile) + 3 new guard tests (opus-4-7 → 1M,
sonnet-4-5 → 200K, haiku-4-5 → 200K) with docstring citations to
Anthropic's sources.
BEDROCK_CONTEXT_LENGTHSheader comment so the next contributor who touches this table has
an upstream source of truth.
claude-sonnet-4-5andclaude-haiku-4-5at 200K explicitly(with commentary + guard tests), citing the April 30 2026 release
note that retired the 1M beta for Sonnet 4.5. fix(bedrock): correct context lengths for Claude 4.x models to 1M tokens #16686 left those
lines untouched with no commentary; my worry was that a future
contributor might "helpfully" bump them alongside the others without
knowing Anthropic has actually capped them at 200K now.
Happy for maintainers to close #16686 in favor of this PR, or to
incorporate @mmcclean-aws's commit with authorship preserved and layer
the tests/docs on top — whatever's easier for review.
Type of Change
Changes Made
agent/bedrock_adapter.py(BEDROCK_CONTEXT_LENGTHS):anthropic.claude-opus-4-7: 1_000_000anthropic.claude-opus-4-6: 200_000 → 1_000_000anthropic.claude-sonnet-4-6: 200_000 → 1_000_000the April 30 2026 release note, so future readers have an upstream
source of truth when this table needs another update.
tests/agent/test_bedrock_adapter.py(TestBedrockContextLength):test_claude_opus_4_6,test_claude_sonnet_versioned, andtest_inference_profile_resolvesto assert the new 1M values.test_claude_opus_4_7— guards the new entry + doc-links it.test_claude_sonnet_4_5_is_200k— guards against regressionsthat would re-bump it, citing the retirement release note.
test_claude_haiku_4_5_is_200k— guards against regressionsthat would bump it to 1M.
agent/model_metadata.py's non-BedrockDEFAULT_CONTEXT_LENGTHStablealready lists
claude-opus-4-7,claude-opus-4-6, andclaude-sonnet-4-6at 1M for the chat-completions / Anthropic directpaths. This PR brings the Bedrock-specific fallback table into alignment.
How to Test
Run the focused test module:
Expected:
178 passed.Manual verification with any Claude-on-Bedrock model:
Context window should now show ~1,000,000 (was 200,000).
Verify older Claude models (Sonnet 4 / Opus 4 / 3.x) still display 200K
and that Haiku 4.5 / Sonnet 4.5 still display 200K — those are
Anthropic's current context windows for those models, not stale values.
Checklist
Code
fix(bedrock):,test(bedrock):)scripts/run_tests.sh tests/agent/test_bedrock_adapter.py tests/agent/test_bedrock_1m_context.py tests/agent/test_bedrock_integration.py -q— 178 passedus.anthropic.claude-opus-4-7on Bedrockus-east-1Documentation & Housekeeping
BEDROCK_CONTEXT_LENGTHSnow links to Anthropic's models overview andthe April 30 2026 release note
Screenshots / Logs
Net diff against
main(single file, +10/-3):BEDROCK_CONTEXT_LENGTHS: Dict[str, int] = { - # Anthropic Claude models on Bedrock - "anthropic.claude-opus-4-6": 200_000, - "anthropic.claude-sonnet-4-6": 200_000, + # Anthropic Claude models on Bedrock. + # Context windows per Anthropic's official models comparison + # (https://platform.claude.com/docs/en/about-claude/models/overview). + # Opus 4.7 / Opus 4.6 / Sonnet 4.6 have 1M generally available + # (no beta header required as of April 2026). Sonnet 4.5 and Sonnet 4 + # had their `context-1m-2025-08-07` beta retired on April 30, 2026, + # so they are standard 200K; Haiku 4.5 is 200K. + "anthropic.claude-opus-4-7": 1_000_000, + "anthropic.claude-opus-4-6": 1_000_000, + "anthropic.claude-sonnet-4-6": 1_000_000, "anthropic.claude-sonnet-4-5": 200_000, "anthropic.claude-haiku-4-5": 200_000, "anthropic.claude-opus-4": 200_000,