Description
All Claude models fail with HTTP 400 when using OAuth authentication (Claude subscription). The error started on 2026-03-17 with no configuration changes. Non-Anthropic models (e.g., GPT-5-nano) work fine.
Root Cause
OpenCode's bundled @ai-sdk/anthropic unconditionally injects cache_control: {"type": "ephemeral"} into system message blocks. This prompt caching metadata appears to no longer be accepted on the OAuth authentication path (Claude subscription). Previously, the Anthropic API silently ignored this field for OAuth requests; as of 2026-03-17, it returns HTTP 400.
Evidence from request body
{
"model": "claude-sonnet-4-6",
"max_tokens": 32000,
"stream": true,
"system": [
{ "type": "text", "text": "...", "cache_control": { "type": "ephemeral" } },
{ "type": "text", "text": "...", "cache_control": { "type": "ephemeral" } },
{ "type": "text", "text": "..." },
{ "type": "text", "text": "..." }
]
}
- No
thinking parameter is present — this is not a thinking/extended-thinking issue.
- The API response is
{"type":"error","error":{"type":"invalid_request_error","message":"Error"}} with status 400.
Confirmed: not a version-specific regression
Tested on both v1.2.27 and v1.2.26 — same error. The cache_control: {"type": "ephemeral"} injection is hardcoded in the bundled @ai-sdk/anthropic (applyCaching()), so downgrading does not help.
Steps to Reproduce
- Authenticate via OAuth (
opencode providers login anthropic)
- Run
opencode run "say hello" --model anthropic/claude-sonnet-4-6
- → HTTP 400
invalid_request_error
Works fine with API key authentication or non-Anthropic providers.
Expected Fix
When the authentication method is OAuth (Claude subscription), strip cache_control from system blocks before sending to the Anthropic API. Prompt caching is an API-tier feature and should not be applied to OAuth-authenticated requests.
Related
Environment
- OpenCode: v1.2.26, v1.2.27 (both affected)
- Auth: OAuth (Claude subscription)
- OS: Linux (WSL2)
Description
All Claude models fail with HTTP 400 when using OAuth authentication (Claude subscription). The error started on 2026-03-17 with no configuration changes. Non-Anthropic models (e.g., GPT-5-nano) work fine.
Root Cause
OpenCode's bundled
@ai-sdk/anthropicunconditionally injectscache_control: {"type": "ephemeral"}into system message blocks. This prompt caching metadata appears to no longer be accepted on the OAuth authentication path (Claude subscription). Previously, the Anthropic API silently ignored this field for OAuth requests; as of 2026-03-17, it returns HTTP 400.Evidence from request body
{ "model": "claude-sonnet-4-6", "max_tokens": 32000, "stream": true, "system": [ { "type": "text", "text": "...", "cache_control": { "type": "ephemeral" } }, { "type": "text", "text": "...", "cache_control": { "type": "ephemeral" } }, { "type": "text", "text": "..." }, { "type": "text", "text": "..." } ] }thinkingparameter is present — this is not a thinking/extended-thinking issue.{"type":"error","error":{"type":"invalid_request_error","message":"Error"}}with status 400.Confirmed: not a version-specific regression
Tested on both v1.2.27 and v1.2.26 — same error. The
cache_control: {"type": "ephemeral"}injection is hardcoded in the bundled@ai-sdk/anthropic(applyCaching()), so downgrading does not help.Steps to Reproduce
opencode providers login anthropic)opencode run "say hello" --model anthropic/claude-sonnet-4-6invalid_request_errorWorks fine with API key authentication or non-Anthropic providers.
Expected Fix
When the authentication method is OAuth (Claude subscription), strip
cache_controlfrom system blocks before sending to the Anthropic API. Prompt caching is an API-tier feature and should not be applied to OAuth-authenticated requests.Related
@ai-sdk/anthropicv2→v3 upgrade PREnvironment