1M tokens for Opus 4.6 #8633

Open
opened 2026-02-16 18:10:26 -05:00 by yindo · 14 comments
Owner

Originally created by @Nepomuk5665 on GitHub (Feb 5, 2026).

Originally assigned to: @fwang on GitHub.

Description

It says: 185,336 19% ($0.00)
When I go over 200k tokens: prompt is too long: 203831 tokens > 200000 maximum
Have tried to turn on:
Image

just tried it with a API key also doesnt allow me to go over 200k tokens.

Found out how to do it! PLEASE add the beta header: betas=["context-1m-2025-08-07"] @fwang

Plugins

OpenCode version

v1.1.52

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

MacOS

Terminal

Terminal

Originally created by @Nepomuk5665 on GitHub (Feb 5, 2026). Originally assigned to: @fwang on GitHub. ### Description It says: 185,336 19% ($0.00) When I go over 200k tokens: prompt is too long: 203831 tokens > 200000 maximum Have tried to turn on: <img width="934" height="99" alt="Image" src="https://github.com/user-attachments/assets/dd09a4c3-15cb-40e4-9c9a-96c924f79ec8" /> just tried it with a API key also doesnt allow me to go over 200k tokens. Found out how to do it! PLEASE add the beta header: betas=["context-1m-2025-08-07"] @fwang ### Plugins - ### OpenCode version v1.1.52 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System MacOS ### Terminal Terminal
yindo added the bugzen labels 2026-02-16 18:10:26 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 5, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8726: Stuck at "prompt is too long" - Reports being stuck with the same "prompt is too long: X tokens > 200000 maximum" error
  • #500: [v0.1.158] [Anthropic: Claude Sonnet 4]: AI_APICallError: prompt is too long: 209840 tokens › 200000 maximum - Similar token limit error with Claude model
  • #5360: prompt is too long - Another instance of exceeding the 200k token limit
  • #12135: TOKEN_REFRESH_NEEDED error incorrectly thrown for context overflow (400 prompt too long) - Related context overflow handling issue

Feel free to ignore if your specific case differs from these existing issues.

@github-actions[bot] commented on GitHub (Feb 5, 2026): This issue might be a duplicate of existing issues. Please check: - #8726: Stuck at "prompt is too long" - Reports being stuck with the same "prompt is too long: X tokens > 200000 maximum" error - #500: [v0.1.158] [Anthropic: Claude Sonnet 4]: AI_APICallError: prompt is too long: 209840 tokens › 200000 maximum - Similar token limit error with Claude model - #5360: prompt is too long - Another instance of exceeding the 200k token limit - #12135: TOKEN_REFRESH_NEEDED error incorrectly thrown for context overflow (400 prompt too long) - Related context overflow handling issue Feel free to ignore if your specific case differs from these existing issues.
Author
Owner

@GeneCodeSavvy commented on GitHub (Feb 5, 2026):

The context-1m-2025-08-07 beta header is currently only added for Sonnet models (claude-sonnet-*), but Opus 4.6 also supports 1M context per Anthropic's docs (https://docs.anthropic.com/en/docs/build-with-claude/context-windows#1m-token-context-window).

The fix would be to simply extend the check to also match claude-opus-4-6.

per the docs, only Sonnet 4 and Sonnet 4.5, Opus 4.6 supports 1M context, so the condition should be specific imho.

should I open a PR with the fix ? @fwang

@GeneCodeSavvy commented on GitHub (Feb 5, 2026): The `context-1m-2025-08-07` beta header is currently only added for Sonnet models (claude-sonnet-*), but Opus 4.6 also supports 1M context per Anthropic's docs (https://docs.anthropic.com/en/docs/build-with-claude/context-windows#1m-token-context-window). The fix would be to simply extend the check to also match claude-opus-4-6. > per the docs, only Sonnet 4 and Sonnet 4.5, Opus 4.6 supports 1M context, so the condition should be specific imho. should I open a PR with the fix ? @fwang
Author
Owner

@okhsunrog commented on GitHub (Feb 5, 2026):

Could you test https://github.com/anomalyco/opencode/pull/12342 ? 1M token window works for me with Opus 4.6, at least I went over 300k tokens without any issues

@okhsunrog commented on GitHub (Feb 5, 2026): Could you test https://github.com/anomalyco/opencode/pull/12342 ? 1M token window works for me with Opus 4.6, at least I went over 300k tokens without any issues
Author
Owner

@okhsunrog commented on GitHub (Feb 5, 2026):

I didn't add context-1m-2025-08-07 header but it still seem to work, can anyone else confirm that? Can you test both with Oauth and Anthropic API?

@okhsunrog commented on GitHub (Feb 5, 2026): I didn't add `context-1m-2025-08-07` header but it still seem to work, can anyone else confirm that? Can you test both with Oauth and Anthropic API?
Author
Owner

@ItsWendell commented on GitHub (Feb 5, 2026):

Just ran into this issue with OAuth Claude Code Max plan on version 1.1.52 @okhsunrog

Image
@ItsWendell commented on GitHub (Feb 5, 2026): Just ran into this issue with OAuth Claude Code Max plan on version 1.1.52 @okhsunrog <img width="903" height="391" alt="Image" src="https://github.com/user-attachments/assets/855539b7-b9f6-406c-9ba1-21874fa22523" />
Author
Owner

@okhsunrog commented on GitHub (Feb 5, 2026):

@ItsWendell are you using my branch? https://github.com/okhsunrog/opencode/tree/feat/opus-4-6-adaptive-thinking
It works for me with Claude Max, OAuth:

Image Image

you can try adding the header context-1m-2025-08-07 and run it, tell me if it works

@okhsunrog commented on GitHub (Feb 5, 2026): @ItsWendell are you using my branch? https://github.com/okhsunrog/opencode/tree/feat/opus-4-6-adaptive-thinking It works for me with Claude Max, OAuth: <img width="557" height="80" alt="Image" src="https://github.com/user-attachments/assets/e34177ac-feab-4cdc-b801-d6b2486e5975" /> <img width="919" height="115" alt="Image" src="https://github.com/user-attachments/assets/334682ab-aeed-4117-9846-51360ea6b5fe" /> you can try adding the header `context-1m-2025-08-07` and run it, tell me if it works
Author
Owner

@ItsWendell commented on GitHub (Feb 5, 2026):

@okhsunrog also mentioning here, there's issues when hitting other thresholds, e.g. 400k tokens:

https://github.com/anomalyco/opencode/pull/12342#issuecomment-3857153765

@ItsWendell commented on GitHub (Feb 5, 2026): @okhsunrog also mentioning here, there's issues when hitting other thresholds, e.g. 400k tokens: https://github.com/anomalyco/opencode/pull/12342#issuecomment-3857153765
Author
Owner
@okhsunrog commented on GitHub (Feb 5, 2026): Added more context in https://github.com/anomalyco/opencode/pull/12342#issuecomment-3857168197 and https://github.com/anomalyco/opencode/pull/12342#issuecomment-3857181334
Author
Owner

@ErcinDedeoglu commented on GitHub (Feb 6, 2026):

This is disrupting flow. It is impossible to use Opus-4.6

@ErcinDedeoglu commented on GitHub (Feb 6, 2026): This is disrupting flow. It is impossible to use Opus-4.6
Author
Owner

@nukeop commented on GitHub (Feb 8, 2026):

This worked for like a day or so (correct 1M context), now it starts compacting the session even before hitting 200 000. It's very disruptive.

@nukeop commented on GitHub (Feb 8, 2026): This worked for like a day or so (correct 1M context), now it starts compacting the session even before hitting 200 000. It's very disruptive.
Author
Owner

@Nepomuk5665 commented on GitHub (Feb 9, 2026):

This worked for like a day or so (correct 1M context), now it starts compacting the session even before hitting 200 000. It's very disruptive.

Adjust context to 1m and add the header: betas=["context-1m-2025-08-07"].

@Nepomuk5665 commented on GitHub (Feb 9, 2026): > This worked for like a day or so (correct 1M context), now it starts compacting the session even before hitting 200 000. It's very disruptive. Adjust context to 1m and add the header: betas=["context-1m-2025-08-07"].
Author
Owner

@nukeop commented on GitHub (Feb 10, 2026):

Still getting prompt is too long even if I manually adjust context length.

@nukeop commented on GitHub (Feb 10, 2026): Still getting `prompt is too long` even if I manually adjust context length.
Author
Owner

@tredondo commented on GitHub (Feb 10, 2026):

@Nepomuk5665 where should this header be added when using OC Desktop?

@tredondo commented on GitHub (Feb 10, 2026): @Nepomuk5665 where should this header be added when using OC Desktop?
Author
Owner

@ItsWendell commented on GitHub (Feb 16, 2026):

For people on bedrock, this has finally be working for me:

Workaround for Bedrock users: unlock 1M context via plugin

Bedrock requires anthropic_beta: ["context-1m-2025-08-07"] in the Converse API request body (via additionalModelRequestFields). OpenCode doesn't set this automatically yet.

The fix is a global plugin that hooks into chat.params and injects the correct provider option. The @ai-sdk/amazon-bedrock SDK then translates it into the right additionalModelRequestFields.anthropic_beta field in the Bedrock Converse API request.

1. Create ~/.config/opencode/plugins/bedrock-1m.ts:

import type { Plugin } from "@opencode-ai/plugin"

const CONTEXT_1M_BETA = "context-1m-2025-08-07"

const SUPPORTED_MODELS = [
  "opus-4-6",
  "opus-4.6",
  "sonnet-4-5",
  "sonnet-4.5",
  "sonnet-4-20250514",
]

export const plugin: Plugin = async () => ({
  "chat.params": async (input, output) => {
    if (input.model.providerID !== "amazon-bedrock") return
    if (!input.model.api.id.includes("claude")) return
    if (!SUPPORTED_MODELS.some((m) => input.model.api.id.includes(m))) return
    const existing = output.options.anthropicBeta ?? []
    if (existing.includes(CONTEXT_1M_BETA)) return
    output.options.anthropicBeta = [...existing, CONTEXT_1M_BETA]
  },
})

2. Add the plugin to ~/.config/opencode/opencode.json:

"plugin": [
  "file:///path/to/your/.config/opencode/plugins/bedrock-1m.ts"
]

Make sure ~/.config/opencode/package.json has @opencode-ai/plugin as a dependency (it should already if you've used plugins before). If not:

{ "dependencies": { "@opencode-ai/plugin": "*" } }

Then run bun install in ~/.config/opencode/ and restart OpenCode.

This works for Claude Opus 4.6, Sonnet 4.5, and Sonnet 4 on all Bedrock inference profiles (global., us., eu., or unprefixed).

@ItsWendell commented on GitHub (Feb 16, 2026): For people on bedrock, this has finally be working for me: **Workaround for Bedrock users: unlock 1M context via plugin** Bedrock requires `anthropic_beta: ["context-1m-2025-08-07"]` in the Converse API request body (via `additionalModelRequestFields`). OpenCode doesn't set this automatically yet. The fix is a global plugin that hooks into `chat.params` and injects the correct provider option. The `@ai-sdk/amazon-bedrock` SDK then translates it into the right `additionalModelRequestFields.anthropic_beta` field in the Bedrock Converse API request. **1. Create `~/.config/opencode/plugins/bedrock-1m.ts`:** ```ts import type { Plugin } from "@opencode-ai/plugin" const CONTEXT_1M_BETA = "context-1m-2025-08-07" const SUPPORTED_MODELS = [ "opus-4-6", "opus-4.6", "sonnet-4-5", "sonnet-4.5", "sonnet-4-20250514", ] export const plugin: Plugin = async () => ({ "chat.params": async (input, output) => { if (input.model.providerID !== "amazon-bedrock") return if (!input.model.api.id.includes("claude")) return if (!SUPPORTED_MODELS.some((m) => input.model.api.id.includes(m))) return const existing = output.options.anthropicBeta ?? [] if (existing.includes(CONTEXT_1M_BETA)) return output.options.anthropicBeta = [...existing, CONTEXT_1M_BETA] }, }) ``` **2. Add the plugin to `~/.config/opencode/opencode.json`:** ```json "plugin": [ "file:///path/to/your/.config/opencode/plugins/bedrock-1m.ts" ] ``` Make sure `~/.config/opencode/package.json` has `@opencode-ai/plugin` as a dependency (it should already if you've used plugins before). If not: ```json { "dependencies": { "@opencode-ai/plugin": "*" } } ``` Then run `bun install` in `~/.config/opencode/` and restart OpenCode. This works for Claude Opus 4.6, Sonnet 4.5, and Sonnet 4 on all Bedrock inference profiles (`global.`, `us.`, `eu.`, or unprefixed).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8633