Claude Code Integration
Claude Code uses Anthropic API style. When integrating with CoreRouter, the key point is that the Base URL does not include /v1, and the API Key is provided via environment variables.
Prerequisites
- VS Code installed.
- Claude Code extension or available Claude Code environment installed.
- API Key created in CoreRouter console.
- Model that supports coding Agents selected.
Required Environment Variables
ANTHROPIC_BASE_URL="https://api.corerouter.cloud"
ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"
ANTHROPIC_MODEL="claude-sonnet-4-5"| Variable | Description |
|---|---|
ANTHROPIC_BASE_URL | CoreRouter Anthropic-compatible endpoint, without /v1 |
ANTHROPIC_AUTH_TOKEN | CoreRouter API Key |
ANTHROPIC_MODEL | Model ID from console, adjustable as needed |
VS Code Extension Configuration
If using Claude Code for VS Code, you can try configuring environment variables in VS Code user settings JSON. Different extension versions may support different configuration key names; if the settings don't take effect, use terminal environment variables as the primary configuration and launch VS Code from that terminal.
Open the command palette, execute Preferences: Open User Settings (JSON), and add:
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.corerouter.cloud" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-xxxxxxxxxxxxxxxx" },
{ "name": "ANTHROPIC_MODEL", "value": "claude-sonnet-4-5" }
]
}macOS / Linux
Temporary configuration:
export ANTHROPIC_BASE_URL="https://api.corerouter.cloud"
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"
export ANTHROPIC_MODEL="claude-sonnet-4-5"Then launch VS Code from the same terminal:
codeFor permanent effect, write to ~/.zshrc or ~/.bashrc:
echo 'export ANTHROPIC_BASE_URL="https://api.corerouter.cloud"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"' >> ~/.zshrc
echo 'export ANTHROPIC_MODEL="claude-sonnet-4-5"' >> ~/.zshrc
source ~/.zshrcWindows PowerShell
Temporary configuration:
$env:ANTHROPIC_BASE_URL="https://api.corerouter.cloud"
$env:ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"
$env:ANTHROPIC_MODEL="claude-sonnet-4-5"Then launch VS Code from the same PowerShell:
codeUser-level permanent configuration:
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://api.corerouter.cloud', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-xxxxxxxxxxxxxxxx', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_MODEL', 'claude-sonnet-4-5', 'User')Takes effect after reopening VS Code.
Test Connection
Please analyze the current project's directory structure and introduce the tech stack of this project.If it can read the project and return analysis results, test Agent capabilities:
Please check if the current project has TypeScript type errors and tell me how to fix them.Interface Address Explanation
Claude Code and OpenAI-compatible clients use different interface formats:
| Tool | Base URL | API Format |
|---|---|---|
| Claude Code | https://api.corerouter.cloud | Anthropic Messages |
| Cline | https://api.corerouter.cloud/v1 | OpenAI Compatible |
Don't use https://api.corerouter.cloud/v1/chat/completions as Claude Code's Endpoint.
Manually Test Anthropic-compatible Endpoint
curl https://api.corerouter.cloud/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello"}
]
}'If your gateway explicitly requires x-api-key authentication, use ANTHROPIC_API_KEY instead and change the Header to x-api-key: $ANTHROPIC_API_KEY.
See Anthropic Messages Integration for more raw API examples.
Call Chain
Claude Code
-> CoreRouter
-> Model channel
-> AI ModelCommon Issues
Environment Variables Not Taking Effect
Close all VS Code windows and re-execute code from the terminal with environment variables set. For Windows user-level environment variables, you may need to restart VS Code or the system.
API Key Invalid Error
Confirm you're using ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY. Also check if the API Key is from the CoreRouter console.
Can Connect But Tools Unavailable
Inspect the specific tool error first:
- If it says
Permission to use Bash has been deniedor mentionsdon't ask mode, check Claude Code's local permissions and allowed commands. In testing, the allowed commandnpm testsucceeded on its own, while adding; echo "exit=$?"caused a denial. Permissions need to match the command actually executed. - For
InputValidationError, missing required arguments, or unexpected arguments, check that the tool name matches its arguments. For example,Greprequirespattern; passing thefile_pathargument used byReadis invalid. Record the version, actual model ID, tool name, and arguments, and inspect the raw API response when diagnosing compatibility. - Confirm that the model supports Tool Calling, Streaming, and Coding Agent, and that CoreRouter's Anthropic-compatible forwarding is enabled.
Tool argument validation and local permission errors alone do not establish an API Key, Base URL, or model-support problem. Preserve intermediate errors and retries even when the task eventually completes.
Token Count or Auxiliary Endpoint Unavailable Error
Different versions of Claude Code may call Anthropic's auxiliary endpoints. CoreRouter primarily forwards Messages requests. If a version strongly depends on additional endpoints, compatibility issues may arise. In this case, first confirm that basic /v1/messages requests work, then consider switching Claude Code versions, using Cline, or contacting support to confirm current interface capabilities.
Should Base URL Include /v1?
Claude Code's environment variable should be https://api.corerouter.cloud. If filled as https://api.corerouter.cloud/v1, the tool may construct incorrect paths.
Security Recommendations
- Use system environment variables to save API Keys.
- Don't write API Keys into project repositories, READMEs, screenshots, or videos.
- Create a separate API Key for Claude Code and set a quota limit.
