Skip to content

fix: only send context-1m beta header for models with >200K context#483

Open
JoaoHenriqueBarbosa wants to merge 5 commits intoKilo-Org:devfrom
JoaoHenriqueBarbosa:fix/conditional-context-1m-beta-header
Open

fix: only send context-1m beta header for models with >200K context#483
JoaoHenriqueBarbosa wants to merge 5 commits intoKilo-Org:devfrom
JoaoHenriqueBarbosa:fix/conditional-context-1m-beta-header

Conversation

@JoaoHenriqueBarbosa
Copy link

@JoaoHenriqueBarbosa JoaoHenriqueBarbosa commented Feb 19, 2026

Context

The context-1m-2025-08-07 anthropic-beta header is unconditionally sent in all Anthropic API requests. This causes "extra usage is required for long context requests" errors for users on plans that don't include the long context beta (e.g. Claude Max plan), even when using standard 200K context models.

Fixes #482
Related: anthropics/claude-code#23700, anthropics/claude-code#23472

Implementation

Two changes in packages/opencode/src/provider/provider.ts:

  1. Removed context-1m-2025-08-07 from the default anthropic-beta header in CUSTOM_LOADERS.anthropic() (line 106) — this header was being sent for every Anthropic API call regardless of the model's context window.

  2. Added conditional logic in getSDK() to append the context-1m-2025-08-07 header only when model.limit.context > 200_000. This way, standard 200K models work normally on all plans, while 1M context models still get the beta header they need.

The check correctly differentiates:

  • Standard models (context: 200000) → no context-1m header
  • 1M models (context: 1000000) → context-1m header appended

No new dependencies, no refactoring, minimal diff.

Changed Files

  • packages/opencode/src/provider/provider.ts — Removed context-1m-2025-08-07 from default headers, added conditional append in getSDK()

How to Test

  1. Configure Kilo with an Anthropic Max plan subscription (or any plan without long context beta access)
  2. Select Claude Opus 4.6 (standard 200K model)
  3. Send a message — should work without the "extra usage is required for long context requests" error
  4. If available, select a 1M context model — the context-1m header should still be sent (verified via debug logs or network inspection)

Get in Touch

Available here on GitHub.

The `context-1m-2025-08-07` anthropic-beta header was unconditionally
sent for all Anthropic API requests. This causes "extra usage is
required for long context requests" errors for users on plans that
don't include the long context beta (e.g. Claude Max plan).

Now the header is only appended when the model's context limit exceeds
200K tokens, which indicates it is a 1M context model that actually
needs the beta.

Fixes anthropics/claude-code#23700
@JoaoHenriqueBarbosa
Copy link
Author

The check-duplicates CI job failed with Executable not found in $PATH: "opencode" — this appears to be a CI infrastructure issue (the duplicate-pr.ts script tries to spawn opencode serve which isn't available in the runner), not related to the changes in this PR.

The check-author and add-contributor-label checks passed. Waiting on check-standards to complete.

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 19, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR moves the context-1m-2025-08-07 Anthropic beta header from being unconditionally applied to all Anthropic models to being conditionally applied only when a model's context limit exceeds 200K tokens. This is a well-targeted fix that prevents "extra usage is required for long context requests" errors for users on plans that don't include the long context beta.

Key observations:

  • The header removal from the global CUSTOM_LOADERS anthropic config (line 106) is correct — it was previously sent for all Anthropic models regardless of context window size.
  • The new conditional logic (lines 1034-1047) properly checks model.api.npm === "@ai-sdk/anthropic" and model.limit.context > 200_000 before appending the header.
  • Edge cases are handled well: duplicate header prevention via includes() check, proper handling of empty vs. existing beta headers, and safe optional chaining on options["headers"].
  • The model.limit.context field is a required z.number() in the Model schema, so no null/undefined risk.
  • The 200K threshold aligns with the existing experimentalOver200K cost field in the Model schema.
Files Reviewed (1 file)
  • packages/opencode/src/provider/provider.ts - 0 issues

JoaoHenriqueBarbosa and others added 3 commits February 19, 2026 17:06
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@JoaoHenriqueBarbosa
Copy link
Author

Hey @chrarnoldus @markijbema @catrielmuller @marius-kilocode, could you take a look at this PR when you get a chance? Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: context-1m-2025-08-07 beta header sent unconditionally causes errors on Claude Max plan

2 participants

Comments