Bug Report
Claude Code Max OAuth authentication fails with error: "This credential is only authorized for use with Claude Code and cannot be used for other API requests."
Environment
- claude-code-mux version: latest (commit f3f5fd7)
- Provider: Anthropic (OAuth - Claude Code Max)
- OAuth token: Successfully loaded and valid
Reproduction
- Authenticate via OAuth using Claude Code Max subscription
- Configure provider with
auth_type = "oauth" and oauth_provider = "anthropic-max"
- Make API request to Claude model
- Observe error from Anthropic API
Logs
2025-11-19T22:45:39.235367Z INFO ccm::server: Loaded 1 OAuth tokens from storage
2025-11-19T22:45:52.898872Z INFO ccm::server: Found 2 provider mappings for model: claude-sonnet-4.5
2025-11-19T22:45:52.898876Z INFO ccm::server: Trying mapping 1/2: provider=claude-max-main, actual_model=claude-sonnet-4-5-20250929
2025-11-19T22:45:53.304162Z INFO ccm::server: Provider claude-max-main failed: Provider API error: 400 - claude-max-main API error: {"type":"error","error":{"type":"invalid_request_error","message":"This credential is only authorized for use with Claude Code and cannot be used for other API requests."},"request_id":"req_011CVJ4RtkjqxsfEdexwMoZR"}, trying next fallback
Current Implementation
File: src/providers/anthropic_compatible.rs (lines 215-219)
OAuth requests currently send:
Authorization: Bearer {access_token}
anthropic-version: 2023-06-01
anthropic-beta: oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
Content-Type: application/json
According to analysis of the official opencode-anthropic-auth package, these headers are correct and match the official implementation.
Possible Causes
Since headers are correct, the issue must be:
- Request body format - CCM might be sending incorrect request body structure
- Endpoint URL - Verify endpoint is exactly
https://api.anthropic.com/v1/messages
- OAuth token issues - Token might not have correct scopes or might be acquired differently
- Request transformation - Something in the Anthropic→Claude translation might be incompatible
Alternative Solution: create_api_key Flow
The codebase includes a create_api_key method (src/auth/oauth.rs line 533) that creates an API key from the OAuth token:
pub async fn create_api_key(&self, provider_id: &str) -> Result<String> {
let access_token = self.get_valid_token(provider_id).await?;
let response = self.http_client
.post("https://api.anthropic.com/api/oauth/claude_cli/create_api_key")
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", access_token))
// ...
}
This method exists but is never called. The official OpenCode implementation offers this as an alternative authentication method labeled "Create an API Key".
Possible workaround:
- On OAuth token acquisition, call
create_api_key() to get an API key
- Store the API key alongside the OAuth token
- Use the API key for API requests instead of the OAuth token
- Refresh API key when OAuth token is refreshed
Additional Context
README claims Claude Code Max is supported:
Yes! Claude Code Mux supports OAuth 2.0 authentication for all three providers:
- Claude Pro/Max: Providers tab → Add Provider → Select "Anthropic" → Choose "OAuth (Claude Pro/Max)"
The OAuth scopes include org:create_api_key, which suggests the create_api_key flow might be the intended approach.
References
Bug Report
Claude Code Max OAuth authentication fails with error: "This credential is only authorized for use with Claude Code and cannot be used for other API requests."
Environment
Reproduction
auth_type = "oauth"andoauth_provider = "anthropic-max"Logs
Current Implementation
File:
src/providers/anthropic_compatible.rs(lines 215-219)OAuth requests currently send:
Authorization: Bearer {access_token}anthropic-version: 2023-06-01anthropic-beta: oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14Content-Type: application/jsonAccording to analysis of the official
opencode-anthropic-authpackage, these headers are correct and match the official implementation.Possible Causes
Since headers are correct, the issue must be:
https://api.anthropic.com/v1/messagesAlternative Solution: create_api_key Flow
The codebase includes a
create_api_keymethod (src/auth/oauth.rsline 533) that creates an API key from the OAuth token:This method exists but is never called. The official OpenCode implementation offers this as an alternative authentication method labeled "Create an API Key".
Possible workaround:
create_api_key()to get an API keyAdditional Context
README claims Claude Code Max is supported:
The OAuth scopes include
org:create_api_key, which suggests the create_api_key flow might be the intended approach.References