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
Closed
feat(zen): enable 1M context window for Opus 4.6 and Sonnet 4.5#12451ruslan-kurchenko wants to merge 1 commit intoanomalyco:devfrom
ruslan-kurchenko wants to merge 1 commit intoanomalyco:devfrom
Conversation
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
Contributor
|
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. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
Author
|
Closing in favor of #12342 which supersedes this PR. This PR only patched the Zen console proxy layer (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (canonical and date-suffixed), negative cases for Opus 4.5, Opus 4.1, Haiku, unknown models, and empty strings.Reviewer Notes
"claude-sonnet-4"(without trailing hyphen) matches both the canonicalclaude-sonnet-4model ID and date-suffixed variants likeclaude-sonnet-4-20250514— while"claude-sonnet-4-5"is listed separately to explicitly cover Sonnet 4.5isSonnet(a looseincludes("sonnet")check) — now uses the samesupports1MContext()for consistencyFixes #12452
Fixes #12438
Fixes #12338
Fixes #11267