Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

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

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

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 Kilo-Org/kilocode#6300
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.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot 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!

@markijbema
Copy link
Contributor

Hi! Thank you for taking the time to contribute to this project—we really appreciate it. 🙏

We are currently working on re-platforming the core of our VS Code and JetBrains extensions to be based on our new Kilo CLI, with a complete rebuild based on OpenCode as our new foundation, and the moment has come to promote this repository to become the main repository. To do that, we moved the code from this repository to the kilocode repository.

This unfortunately means we cannot merge this branch here anymore. Please add https://github.com/Kilo-Org/kilocode.git as a remote, and push your branch there and create a new PR in https://github.com/Kilo-Org/kilocode . We unfortunately cannot do this for you as then the PR would not be in your name anymore. If you need any help, feel free to ask on our Discord in #kilo-dev-contributors

Sorry for the inconvenience and thank you for contributing to Kilo!

@markijbema markijbema closed this Feb 22, 2026
@marius-kilocode
Copy link
Collaborator

@JoaoHenriqueBarbosa since OpenCode removed the SDK support now anyway because of blocked accounts, we probably don't want to follow up on this anyway.

@JoaoHenriqueBarbosa
Copy link
Author

@marius-kilocode no problem! Anyway I feel happy to be considered and for your answers, thank you!

@JoaoHenriqueBarbosa JoaoHenriqueBarbosa deleted the fix/conditional-context-1m-beta-header branch February 24, 2026 12:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

4 participants