Skip to content

fix(bedrock): align Claude context-window table with Anthropic docs - #24059

Closed
patrick-muller wants to merge 3 commits into
NousResearch:mainfrom
patrick-muller:fix/bedrock-claude-1m-context-table
Closed

fix(bedrock): align Claude context-window table with Anthropic docs#24059
patrick-muller wants to merge 3 commits into
NousResearch:mainfrom
patrick-muller:fix/bedrock-claude-1m-context-table

Conversation

@patrick-muller

@patrick-muller patrick-muller commented May 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The BEDROCK_CONTEXT_LENGTHS table in agent/bedrock_adapter.py reported
stale values for recent Anthropic Claude models on Bedrock:

  • No entry for claude-opus-4-7 — falls through via substring match to
    the generic claude-opus-4 entry at 200K, i.e. 5x too small.
  • claude-opus-4-6 reported 200K, but is 1M generally available.
  • claude-sonnet-4-6 reported 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 compression
threshold (compression.threshold * context_length), and subagent
context 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 AnthropicBedrock SDK via api_mode: anthropic_messages exactly
as 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"):

Bedrock model ID Before After Anthropic docs
anthropic.claude-opus-4-7 (missing) 1_000_000 1M tokens
anthropic.claude-opus-4-6 200_000 1_000_000 1M tokens
anthropic.claude-sonnet-4-6 200_000 1_000_000 1M tokens
anthropic.claude-sonnet-4-5 200_000 200_000 (unchanged) 200K (1M beta retired Apr 30 2026)
anthropic.claude-haiku-4-5 200_000 200_000 (unchanged) 200k tokens

Why Sonnet 4.5 and Haiku 4.5 remain at 200K — and claude-opus-4 /
claude-sonnet-4 / claude-3-* also remain at 200K:

  • Sonnet 4.5: per the April 30, 2026 release note,

    "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."

  • Haiku 4.5: listed as 200k tokens in the Anthropic models comparison.
  • Sonnet 4 / Opus 4 / Claude 3: never had 1M support.

Related Issue

No existing issue — discovered while running us.anthropic.claude-opus-4-7
on Bedrock and seeing a 200K window displayed instead of 1M.

Related (but distinct) bugs in the same resolution chain:

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, bump claude-opus-4-6 and claude-sonnet-4-6 to 1M).
This PR is a superset of that work:

  • Identical source diff to fix(bedrock): correct context lengths for Claude 4.x models to 1M tokens #16686 on those three entries.
  • Adds tests — 3 updated assertions (opus-4-6, sonnet-4-6 versioned,
    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.
  • Adds inline Anthropic-doc citations in the BEDROCK_CONTEXT_LENGTHS
    header comment so the next contributor who touches this table has
    an upstream source of truth.
  • Leaves claude-sonnet-4-5 and claude-haiku-4-5 at 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/bedrock_adapter.py (BEDROCK_CONTEXT_LENGTHS):
    • Add anthropic.claude-opus-4-7: 1_000_000
    • Change anthropic.claude-opus-4-6: 200_000 → 1_000_000
    • Change anthropic.claude-sonnet-4-6: 200_000 → 1_000_000
    • Update header comment with links to Anthropic's models overview and
      the 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):
    • Update test_claude_opus_4_6, test_claude_sonnet_versioned, and
      test_inference_profile_resolves to assert the new 1M values.
    • Add test_claude_opus_4_7 — guards the new entry + doc-links it.
    • Add test_claude_sonnet_4_5_is_200k — guards against regressions
      that would re-bump it, citing the retirement release note.
    • Add test_claude_haiku_4_5_is_200k — guards against regressions
      that would bump it to 1M.

agent/model_metadata.py's non-Bedrock DEFAULT_CONTEXT_LENGTHS table
already lists claude-opus-4-7, claude-opus-4-6, and
claude-sonnet-4-6 at 1M for the chat-completions / Anthropic direct
paths. This PR brings the Bedrock-specific fallback table into alignment.

How to Test

  1. Run the focused test module:

    scripts/run_tests.sh tests/agent/test_bedrock_adapter.py tests/agent/test_bedrock_1m_context.py tests/agent/test_bedrock_integration.py -q
    

    Expected: 178 passed.

  2. Manual verification with any Claude-on-Bedrock model:

    hermes --model us.anthropic.claude-opus-4-7 --provider bedrock
    > /usage
    

    Context window should now show ~1,000,000 (was 200,000).

  3. 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

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(bedrock):, test(bedrock):)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix (no unrelated commits)
  • I've run 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 passed
  • I've added tests for my changes (3 new tests doc-linking Anthropic's published context windows)
  • I've tested on my platform: macOS 26.3 (Apple Silicon), Python 3.11, against us.anthropic.claude-opus-4-7 on Bedrock us-east-1

Documentation & Housekeeping

  • I've updated relevant documentation — header comment in
    BEDROCK_CONTEXT_LENGTHS now links to Anthropic's models overview and
    the April 30 2026 release note
  • N/A — no config keys added or changed
  • N/A — no architecture or workflow changes
  • N/A — no file I/O, process management, or cross-platform code touched
  • N/A — no tool descriptions or schemas changed

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,

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API labels May 12, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

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.
@patrick-muller patrick-muller changed the title fix(bedrock): raise Claude 4.x context window to 1M and add opus-4-7 fix(bedrock): align Claude context-window table with Anthropic docs May 12, 2026
@patrick-muller

Copy link
Copy Markdown
Contributor Author

Thanks for the spot! Quick clarification so the comparison is accurate:

#16686 also adds the claude-opus-4-7 entry — that's not actually a difference between the two PRs. And we don't really change sonnet-4-5 / haiku-4-5 either; both PRs leave those entries at 200_000. The source diff on those two lines is zero in both.

The actual delta vs #16686:

  • Tests. fix(bedrock): correct context lengths for Claude 4.x models to 1M tokens #16686 has no tests. This PR updates 3 existing assertions (opus-4-6, sonnet-4-6-versioned, inference-profile) and adds 3 new guard tests: test_claude_opus_4_7 (→ 1M), test_claude_sonnet_4_5_is_200k, test_claude_haiku_4_5_is_200k, each with Anthropic-doc citations in the docstring.
  • Anthropic-doc citations in the BEDROCK_CONTEXT_LENGTHS header comment pointing at the models overview + the April 30 2026 release note, so the next contributor has an upstream source of truth.
  • Explicit "stay at 200K" decision for sonnet-4-5 and haiku-4-5. fix(bedrock): correct context lengths for Claude 4.x models to 1M tokens #16686 leaves those lines alone without commentary — my concern is that someone reading this table in 3 months might "helpfully" bump them alongside the others without knowing the 1M beta was retired for Sonnet 4.5 on Apr 30 2026 and that Haiku 4.5 is genuinely a 200K model. The guard tests + inline comment pin those values so that mistake can't silently land.

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.

@mmcclean-aws

Copy link
Copy Markdown
Contributor

Happy to close #16686 and use this PR as it has the tests missing from my PR

@teknium1 teknium1 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.

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-4 fallback (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.py comment.
  • Keep a behavior-focused lookup invariant instead of adding per-model snapshot guards.

Automated hermes-sweeper review.

Comment thread agent/bedrock_adapter.py
# (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,

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.

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.

@alt-glitch alt-glitch added provider/bedrock AWS Bedrock (boto3, IAM) P3 Low — cosmetic, nice to have and removed provider/anthropic Anthropic native Messages API P2 Medium — degraded but workaround exists labels Jul 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Supersedes #16686 (now closed, not merged) — same core BEDROCK_CONTEXT_LENGTHS bump to 1M for Claude 4.x, but this PR adds the guard tests + Anthropic-doc citations #16686 lacked, and #16686's author agreed to close in its favor. This is the earliest-open canonical of the Bedrock 1M-context family (#54901/#54914/#54918 dedupe here). Related, not a duplicate, since the superseded PR is already closed.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

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!

#67977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/bedrock AWS Bedrock (boto3, IAM) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants