-
Notifications
You must be signed in to change notification settings - Fork 14.8k
bug: OAuth auth + cache_control ephemeral causes HTTP 400 on all Claude models since 2026-03-17 #17910
Description
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
thinkingparameter 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
- [Question]: How does oh-my-opencode map the 'max' variant for native Anthropic provider models like claude-opus-4-6? code-yeongyu/oh-my-openagent#2630 — Same breakage reported on 2026-03-17, "was working on 2026-03-16, broke on 2026-03-17 with no config changes"
- bug: Claude Sonnet 4.5 with thinking + ephemeral cache returns HTTP 400 #17883 — Previously filed as thinking + ephemeral conflict, but the actual root cause is OAuth + ephemeral
- feat(provider): add adaptive thinking and 1M context support for Claude Opus 4.6 #12342 — Pending
@ai-sdk/anthropicv2→v3 upgrade PR
Environment
- OpenCode: v1.2.26, v1.2.27 (both affected)
- Auth: OAuth (Claude subscription)
- OS: Linux (WSL2)