Command-line toolsAnthropic-compatible

How to use Claude Code with a custom Anthropic API endpoint

Point Claude Code at a third-party Anthropic-compatible API with ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN — shell, settings.json and VS Code examples plus fixes.

Last updated:Claude Code Official site

Copy-paste configuration

These are the three values the tool needs. Create the API key on the API Keys page of your CCSub dashboard.

ANTHROPIC_BASE_URL
https://www.ccsub.net(no /v1, no trailing slash)
ANTHROPIC_AUTH_TOKEN
sk-your-ccsub-key
Model (optional)
claude-sonnet-5(switch any time with /model)
macOS / Linux — append to ~/.zshrc (or ~/.bashrc)
echo 'export ANTHROPIC_BASE_URL="https://www.ccsub.net"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-your-key"' >> ~/.zshrc
source ~/.zshrc
claude

For model, use an ID such as claude-sonnet-5 — the full list of model IDs is on the models page. No key yet? Create an account first.

Steps at a glance

  1. 1

    Install Claude Code

    Install Node.js 18 or newer, then run npm install -g @anthropic-ai/claude-code@latest (prefix with sudo on macOS/Linux if npm needs it). Check it with claude --version.

  2. 2

    Create a CCSub API key

    Sign up for CCSub, open the API Keys page in the dashboard, create a key and copy the sk- value.

  3. 3

    Set two environment variables

    Set ANTHROPIC_BASE_URL to https://www.ccsub.net and ANTHROPIC_AUTH_TOKEN to your key, in your shell profile, as Windows user variables, or in the env block of ~/.claude/settings.json.

  4. 4

    Open a new terminal and run claude

    Close every terminal window, open a new one in your project folder and run claude. Accept the defaults on first launch.

  5. 5

    Confirm the route

    Run /status inside Claude Code and check that Anthropic base URL shows https://www.ccsub.net, then send a message and find it on the Usage page of the CCSub dashboard.

Claude Code is Anthropic's agentic coding tool for the terminal, and it only speaks the Anthropic Messages API. That keeps the setup short: no Claude account login and no code changes. You tell Claude Code where to send requests (ANTHROPIC_BASE_URL) and which credential to send (ANTHROPIC_AUTH_TOKEN). Anthropic documents this as connecting Claude Code to an "LLM gateway", and CCSub works the same way.

The two variables

What Claude Code needs
ANTHROPIC_BASE_URL
https://www.ccsub.netEndpoint root. No /v1, no trailing slash.
ANTHROPIC_AUTH_TOKEN
sk-your-ccsub-keyCreated on the API Keys page; sent as Authorization: Bearer.
ANTHROPIC_MODEL (optional)
claude-sonnet-5Pins a default model. You can also switch with /model.

The mistake we see most often is a /v1 suffix. Claude Code builds the request path itself, so https://www.ccsub.net becomes https://www.ccsub.net/v1/messages. If you enter https://www.ccsub.net/v1, the request goes to /v1/v1/messages and fails.

macOS and Linux

Check your shell with echo $SHELL. If it ends in zsh, edit ~/.zshrc; if it ends in bash, edit ~/.bashrc:

echo 'export ANTHROPIC_BASE_URL="https://www.ccsub.net"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-your-key"' >> ~/.zshrc
source ~/.zshrc

Run echo $ANTHROPIC_BASE_URL afterwards. If it prints the URL, the current window has picked it up.

Windows (PowerShell)

Store the values as user environment variables so every new terminal sees them:

[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://www.ccsub.net', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-your-key', 'User')

Then close all PowerShell and terminal windows. Windows does not push new variables into windows that are already open, and the same goes for the integrated terminal inside VS Code or Cursor: quit the editor and start it again.

Using settings.json instead

If you would rather not touch system variables, put the values in Claude Code's own settings file, ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows). It applies to every project, including background sessions:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.ccsub.net",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key"
  }
}

If the file already has other settings, merge the env block in and watch your commas. When the same variable is set both in your shell and in settings.json, the settings file wins — check it first if a shell change seems to do nothing.

For a single project, use .claude/settings.local.json. Do not put the key in a project's .claude/settings.json: that file is normally committed, so the key would travel with the repository. Project-level files also only apply after you accept the folder trust prompt.

The VS Code extension

The Claude Code extension checks credentials before it launches, and that check does not read ~/.claude/settings.json. Anthropic's docs recommend VS Code's own user settings instead. Run Preferences: Open User Settings (JSON) and add:

{
  "claudeCode.environmentVariables": [
    { "name": "ANTHROPIC_BASE_URL", "value": "https://www.ccsub.net" },
    { "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-your-key" }
  ]
}

Start a session and confirm the route

cd ~/your-project
claude

Accept the defaults on first launch. Type /model to choose a model; the model field takes IDs such as claude-sonnet-5, and every available ID is listed on the models page.

Two ways to confirm traffic really goes through CCSub:

  1. Run /status. The Status tab should show an Anthropic base URL line with https://www.ccsub.net and an Auth token line naming ANTHROPIC_AUTH_TOKEN. If the base URL line is missing, the variable did not reach the session.
  2. Check the bill: send one message, then open Usage in the CCSub dashboard. If the request and its token counts show up, you are done.

Before opening Claude Code at all, you can test the URL and key with curl. A JSON body starting with {"id":"msg_ means everything works; a 401 means the key is wrong:

curl -sS -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'

Multiple credentials fight each other. If you previously signed in with a claude.ai account and then set ANTHROPIC_AUTH_TOKEN, Claude Code shows a startup warning ending in auth may not work as expected (older versions say Auth conflict: Both a token ... and an API key ... are set). Requests use the token, but the stale login can cause odd auth behaviour. Run /logout inside Claude Code to clear it.

Switching between providers

If you move between CCSub and other API providers, editing variables every time gets old. CC Switch is a desktop app that swaps Claude Code providers with one click, and CCSub is already in its preset list. For OpenAI's terminal agent, see the Codex CLI guide.

A note on cost

Every turn in Claude Code resends the conversation so far, so input tokens grow over a long session. On CCSub, cache reads and writes for regular accounts are billed at the input price, which means /clear when you change topics and /compact for long threads are the simplest ways to keep usage down. Each request's charge is itemised on the Usage page.

Common errors and fixes

401 authentication_error: Missing or invalid API key

Cause:ANTHROPIC_AUTH_TOKEN is not set in this shell, the key was pasted with extra whitespace, or the key is disabled.

Fix:Run echo $ANTHROPIC_AUTH_TOKEN to check the value, make sure the key is enabled in the dashboard, then open a fresh terminal.

Stuck on “Connecting…”, Connection refused, or timeouts

Cause:The base URL has a /v1 suffix or a trailing slash, or a local proxy/VPN is intercepting terminal traffic.

Fix:Set ANTHROPIC_BASE_URL back to exactly https://www.ccsub.net and retry with the proxy client turned off.

API returned an empty or malformed response (HTTP 200)

Cause:The request path is wrong, so the server answers with a web page instead of an API response — usually an extra /v1 or /api in the base URL.

Fix:Use the bare https://www.ccsub.net with no path.

Claude Code still asks me to log in

Cause:The token is only in a project's .claude/settings.json or settings.local.json, which applies after the folder trust prompt, or the VS Code extension cannot see ~/.claude/settings.json.

Fix:Set the token in your shell or ~/.claude/settings.json; for the extension use claudeCode.environmentVariables.

402 insufficient_balance

Cause:Your balance does not cover the estimated cost of the request, or a monthly plan's daily quota is used up.

Fix:Top up your balance. Monthly plan quotas reset at 00:00 Beijing time (UTC+8); once the day's quota is spent, requests draw from your balance.

404 Unknown model

Cause:The model field contains a display name or a typo instead of a model ID.

Fix:Use the hyphenated ID, e.g. claude-sonnet-5, exactly as listed on the models page.

For more error messages and what they mean, see the error troubleshooting index. Installation and network issues are covered in the troubleshooting docs (Chinese).

FAQ

Should ANTHROPIC_BASE_URL end with /v1?

No. Claude Code appends /v1/messages itself, so use https://www.ccsub.net. Adding /v1 produces /v1/v1/messages and the request fails.

ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY?

Use ANTHROPIC_AUTH_TOKEN, as in the CCSub docs. It is sent as an Authorization: Bearer header and takes effect immediately without a login screen. ANTHROPIC_API_KEY needs a one-time approval in interactive mode, and a key you once declined is silently ignored. CCSub accepts either header.

I set the variables but Claude Code still talks to Anthropic. Why?

Terminals only read environment variables when they start, so open a new one. Inside Claude Code, run /status: if there is no Anthropic base URL line, the variable never reached the session.

How do I configure the Claude Code VS Code extension?

Anthropic's docs recommend VS Code's own user settings: run Preferences: Open User Settings (JSON) and add claudeCode.environmentVariables with ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. Values in ~/.claude/settings.json reach the spawned process but not the extension's own login check.

What do I put as the model?

Pick one with /model inside a session, or pin a default by adding ANTHROPIC_MODEL (for example claude-sonnet-5) to the env block. The full list of model IDs is on the CCSub models page.

See all integration guides

Need a CCSub API key?

Sign up, create a key in the dashboard, and paste the values above into your tool. Pay-as-you-go balance does not expire — you only pay for the tokens you use.