Skip to content

feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#12451

Closed
ruslan-kurchenko wants to merge 1 commit intoanomalyco:devfrom
ruslan-kurchenko:feat/opus-1m-context-window
Closed

feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#12451
ruslan-kurchenko wants to merge 1 commit intoanomalyco:devfrom
ruslan-kurchenko:feat/opus-1m-context-window

Conversation

@ruslan-kurchenko
Copy link

@ruslan-kurchenko ruslan-kurchenko commented Feb 6, 2026

Summary

Extends the Anthropic 1M context window beta to Claude Opus 4.6 and Claude Sonnet 4.5 models. Previously only Sonnet 4 variants could leverage the extended context — this unlocks it for the newest high-capability models across both direct API and Bedrock paths.

Problem & Solution

Problem: The context-1m-2025-08-07 beta header was only sent for models matching claude-sonnet-*, so Opus 4.6 and Sonnet 4.5 users hit the default context limit despite the models supporting 1M tokens.

Solution: Replace the inline prefix check with a dedicated supports1MContext() predicate that matches all eligible model families, applied consistently to both API paths.

Key Changes

  • Introduce supports1MContext() — a single source of truth for which models get the 1M context beta
  • Apply the beta flag consistently across direct Anthropic API and AWS Bedrock request paths
  • Cover Opus 4.6, Sonnet 4.5, and Sonnet 4 model families (with snapshot date suffixes)

System Design

Beta Header Injection Flow

sequenceDiagram
    participant Client
    participant Handler as handler.ts
    participant Select as selectProvider()
    participant Helper as anthropicHelper
    participant API as Anthropic API / Bedrock

    Client->>Handler: POST /zen (model: claude-opus-4-6)
    Handler->>Select: selectProvider(model)
    Select-->>Handler: providerInfo (anthropicHelper)

    rect rgb(40, 40, 40)
        note right of Handler: Request modification
        Handler->>Helper: modifyHeaders(headers, body, apiKey)
        Helper->>Helper: supports1MContext(body.model)?
        alt Model supported
            Helper-->>Handler: set anthropic-beta: context-1m-2025-08-07
        else Model not supported
            Helper-->>Handler: no beta header
        end
        Handler->>Helper: modifyBody(body)
        note right of Helper: Bedrock: injects anthropic_beta field
    end

    Handler->>API: fetch(url, { headers, body })
    API-->>Client: Response (up to 1M context)
Loading

The change affects the decision point inside modifyHeaders and modifyBody — replacing a hardcoded claude-sonnet- prefix check with supports1MContext() that covers three model prefixes.

Testing Strategy

The supports1MContext() helper is tested against all model families: positive cases for Opus 4.6, Sonnet 4.5, and Sonnet 4 (canonical and date-suffixed), negative cases for Opus 4.5, Opus 4.1, Haiku, unknown models, and empty strings.

Reviewer Notes

  • The prefix "claude-sonnet-4" (without trailing hyphen) matches both the canonical claude-sonnet-4 model ID and date-suffixed variants like claude-sonnet-4-20250514 — while "claude-sonnet-4-5" is listed separately to explicitly cover Sonnet 4.5
  • Bedrock path previously used isSonnet (a loose includes("sonnet") check) — now uses the same supports1MContext() for consistency

Fixes #12452
Fixes #12438
Fixes #12338
Fixes #11267

Extend the Anthropic context-1m beta header beyond Sonnet 4 to also
cover Claude Opus 4.6 and Claude Sonnet 4.5 models, for both direct
API and Bedrock paths.

- Extract supports1MContext() helper with prefix-based model matching
- Replace inline startsWith check and remove isSonnet variable
- Hoist beta version string into CONTEXT_1M_BETA constant
- Add 12 unit tests covering supported, unsupported, and edge cases
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@ruslan-kurchenko
Copy link
Author

Closing in favor of #12342 which supersedes this PR.

This PR only patched the Zen console proxy layer (anthropic-beta header in modifyHeaders/modifyBody), but #12342 is a comprehensive solution that also addresses:

  • Core runtime beta header — adds adaptive-thinking-2026-01-28 + context-1m-2025-08-07 headers in provider.ts (where @ai-sdk/anthropic SDK calls actually happen)
  • Adaptive thinking for Opus 4.6 — uses effort-based thinking instead of fixed budgetTokens
  • Compaction overflow fix — correctly compares input tokens against model.limit.input instead of combined total, preventing premature/incorrect compaction
  • models.dev limit.input — companion PR fix(opencode): add input token limit for Claude Opus 4.6 models.dev#819 adds the input token limit for Opus 4.6
  • AI SDK v5→v6 upgrade@ai-sdk/anthropic v2→v3, LanguageModelV2LanguageModelV3

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

Labels

None yet

Projects

None yet

1 participant