Skip to content

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 ​

bash
ANTHROPIC_BASE_URL="https://api.corerouter.cloud"
ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxxxxxx"
ANTHROPIC_MODEL="claude-sonnet-4-5"
VariableDescription
ANTHROPIC_BASE_URLCoreRouter Anthropic-compatible endpoint, without /v1
ANTHROPIC_AUTH_TOKENCoreRouter API Key
ANTHROPIC_MODELModel 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:

json
{
  "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:

bash
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:

bash
code

For permanent effect, write to ~/.zshrc or ~/.bashrc:

bash
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 ~/.zshrc

Windows PowerShell ​

Temporary configuration:

powershell
$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:

powershell
code

User-level permanent configuration:

powershell
[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 ​

text
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:

text
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:

ToolBase URLAPI Format
Claude Codehttps://api.corerouter.cloudAnthropic Messages
Clinehttps://api.corerouter.cloud/v1OpenAI Compatible

Don't use https://api.corerouter.cloud/v1/chat/completions as Claude Code's Endpoint.

Manually Test Anthropic-compatible Endpoint ​

bash
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 ​

text
Claude Code
   -> CoreRouter
   -> New API compatibility layer
   -> Model channel
   -> AI Model

Common 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 ​

Switch to a model that supports Tool Calling, Streaming, and Coding Agent, and check if CoreRouter's Anthropic-compatible forwarding is enabled.

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.

Released under the MIT License.