feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#1
feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#1ruslan-kurchenko wants to merge 1 commit intodevfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc822bc94e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const CONTEXT_1M_BETA = "context-1m-2025-08-07" | ||
|
|
||
| export function supports1MContext(model: string): boolean { | ||
| const prefixes = ["claude-opus-4-6", "claude-sonnet-4-5", "claude-sonnet-4-"] |
There was a problem hiding this comment.
Match canonical Sonnet 4 model for 1M context
The new prefix list excludes the documented claude-sonnet-4 model ID because it only matches claude-sonnet-4-... (with a trailing hyphen). When users request claude-sonnet-4, supports1MContext() returns false, so anthropic-beta: context-1m-2025-08-07 is no longer sent on either the direct Anthropic path or the Bedrock anthropic_beta path, which regresses that model back to the default context limit.
Useful? React with 👍 / 👎.
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
fc822bc to
2007403
Compare
|
Closing in favor of anomalyco#12342 which supersedes this PR. This PR only patched the Zen console proxy layer, while anomalyco#12342 provides a complete solution including core runtime beta headers, adaptive thinking for Opus 4.6, compaction overflow fix, and AI SDK v5→v6 upgrade. |
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-07beta header was only sent for models matchingclaude-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
supports1MContext()— a single source of truth for which models get the 1M context betaSystem 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)The change affects the decision point inside
modifyHeadersandmodifyBody— replacing a hardcodedclaude-sonnet-prefix check withsupports1MContext()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 (with and without snapshot suffixes), negative cases for Opus 4.5, Opus 4.1, Haiku, unknown models, and empty strings.Reviewer Notes
["claude-opus-4-6", "claude-sonnet-4-5", "claude-sonnet-4-"]intentionally uses a trailing hyphen onclaude-sonnet-4-to match Sonnet 4 snapshots (e.g.,claude-sonnet-4-20250514) without matching Sonnet 4.5 twice — Sonnet 4.5 is caught by its own explicit prefix firstisSonnet(a looseincludes("sonnet")check) — now uses the samesupports1MContext()for consistency