You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: How does opencode work with Claude Code OAuth tokens when AI SDK fails? #417
Hi! I'm trying to understand how opencode successfully uses Claude Code OAuth tokens with the Anthropic API, as I'm getting restrictions when trying to replicate the same approach.
I've been studying opencode's implementation to understand how it integrates with Claude Code OAuth. Based on my analysis of the codebase, opencode uses:
When I try to replicate this exact approach using Claude Code OAuth tokens, I get this error:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "system: This credential is only authorized for use with Claude Code and cannot be used for other API requests."
}
}
So I have a few questions:
How does opencode bypass this restriction? The error suggests Claude Code OAuth tokens are restricted to "Claude Code" only, but opencode successfully uses them.
Is there a special endpoint or configuration? Does opencode use a different API endpoint, special headers, or application registration that allows it to work?
Application whitelisting? Is opencode specifically whitelisted by Anthropic to use Claude Code OAuth tokens?
Token scopes or format? Are there specific OAuth scopes or token formats that opencode requests that differ from standard Claude Code tokens?
So far I've tried
Used identical headers and fetch configuration as opencode
Tried console.anthropic.com endpoint instead of api.anthropic.com
Verified token format matches opencode's auth.json structure
Used same AI SDK version and configuration
I expected to be able to use Claude Code OAuth tokens with the AI SDK following opencode's implementation pattern, since opencode clearly demonstrates this is possible.
Environment Details
Node.js v22.17.0
@ai-sdk/anthropic v1.2.12
ai SDK (latest)
Any insights into how opencode's Anthropic integration works would be greatly appreciated! The codebase shows it's using standard AI SDK patterns, but there must be something special about how it's configured or registered with Anthropic.
Thanks in advance guys, and great job on the product. I've loved using it.
It's possible, and the solution is so silly that I laughed when I finally figured it out. I'm not sure if I should just post it plainly here since Anthropic might block it which would affect opencode as well, but here's a hint. After you exhaust every option and you're sure the requests you're sending are identical to CC's, check the one thing that probably still isn't identical yet (hint: it comes AFTER the headers).
Reacted by Patrick Lee, conradkoh, stylezdevops, Sashmit Bhaduri, N Digvijay, Arseni Ivanov, Henrique Borsatto de Campos, Konrad Iturbe, mudkip, Roosemberth Palacios and 4 more
Activity
aShanki commentedon Jun 26, 2025
I'm taking my API tokens straight from the
~/.claude/.credentials.jsonbtw. I'm not sure if that makes a huge difference or not.thdxr commentedon Jun 26, 2025
hey unfortunately we can't provide any specific instructions for this
aShanki commentedon Jun 26, 2025
Disappointing. I really want to be able to use my subscription for personal use, but that seems impossible.
nam20485 commentedon Sep 3, 2025
one word: repositories view
baleti commentedon Sep 12, 2025
what do you mean?
TKasperczyk commentedon Dec 7, 2025
It's possible, and the solution is so silly that I laughed when I finally figured it out. I'm not sure if I should just post it plainly here since Anthropic might block it which would affect opencode as well, but here's a hint. After you exhaust every option and you're sure the requests you're sending are identical to CC's, check the one thing that probably still isn't identical yet (hint: it comes AFTER the headers).
v0.2.10: Add OAuth beta header for Claude API authentication
Merge pull request anomalyco#417 from affaan-m/codex/orchestration-ha…