Skip to content

Integrating with Claude Code ​

TokenSG is natively compatible with the Anthropic Messages API (/v1/messages) and can serve as the custom upstream for the Claude Code CLI. Two environment variables are all that's needed — no changes to Claude Code itself.

Prerequisites ​

Configuration ​

Claude Code recognizes custom upstreams via two environment variables:

VariableValueNotes
ANTHROPIC_BASE_URLhttps://api.tokensg.aiTokenSG gateway root (no /v1 suffix — Claude Code appends it automatically)
ANTHROPIC_AUTH_TOKENsk-<your-tokensg-key>Sends Authorization: Bearer <token>, matching TokenSG auth

Why not ANTHROPIC_API_KEY?

ANTHROPIC_API_KEY sends the x-api-key header (Anthropic's official style). TokenSG uses OpenAI-style Bearer auth, so you must use ANTHROPIC_AUTH_TOKEN. Use one or the other — never both.

Add to ~/.claude/settings.json (global) or .claude/settings.json at project root:

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.tokensg.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-tokensg-key"
  }
}

Restart Claude Code to pick up the change.

Option B — Current session only ​

bash
export ANTHROPIC_BASE_URL="https://api.tokensg.ai"
export ANTHROPIC_AUTH_TOKEN="sk-your-tokensg-key"
claude
powershell
$env:ANTHROPIC_BASE_URL = "https://api.tokensg.ai"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-tokensg-key"
claude
cmd
set ANTHROPIC_BASE_URL=https://api.tokensg.ai
set ANTHROPIC_AUTH_TOKEN=sk-your-tokensg-key
claude

Option C — Persist in shell profile ​

Add the two export lines from Option B to ~/.bashrc / ~/.zshrc (Linux/macOS), or set them as user environment variables on Windows.

Model Routing (required) ​

Claude Code's default model IDs do not fully match the IDs TokenSG currently ships. Without explicit mapping via environment variables you'll get 404 model not found.

Claude models available on TokenSG ​

TokenSG model IDOfficial modelContextMax output tokens
claude-opus-4-6Claude Opus 4.61M (beta)32K
claude-sonnet-4-6Claude Sonnet 4.61M (beta)64K
claude-3-5-sonnet-20241022Claude Sonnet 3.5 (v2)200K8K
claude-3-5-haiku-20241022Claude Haiku 3.5200K8K

Authoritative list comes from /v1/models at runtime.

1M context note: Opus 4.6 / Sonnet 4.6's 1M context is an Anthropic beta and requires the header anthropic-beta: context-1m-2025-08-07. Without it the effective window is 200K. Claude Code doesn't currently inject this header — use a proxy or wait for native support if you actually need 1M.

Claude 4.7 isn't on TokenSG yet; request access via Admin → Models if needed.

In ~/.claude/settings.json, pin model slots explicitly:

json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.tokensg.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-tokensg-key",
    "ANTHROPIC_MODEL": "claude-opus-4-6",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-6",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-3-5-haiku-20241022"
  }
}
VariablePurposeRecommended
ANTHROPIC_MODELSession main model (code generation, multi-step reasoning)claude-opus-4-6 or claude-sonnet-4-6
ANTHROPIC_DEFAULT_OPUS_MODELModel ID that the opus alias resolves toclaude-opus-4-6
ANTHROPIC_DEFAULT_SONNET_MODELModel ID that the sonnet alias resolves toclaude-sonnet-4-6
ANTHROPIC_DEFAULT_HAIKU_MODELModel ID that the haiku alias resolves toclaude-3-5-haiku-20241022

ANTHROPIC_SMALL_FAST_MODEL is deprecated

Older Claude Code versions used ANTHROPIC_SMALL_FAST_MODEL for the fast / low-cost slot. This variable has been replaced by ANTHROPIC_DEFAULT_HAIKU_MODEL. If you have both set, the new variable takes precedence.

Setting only BASE_URL + AUTH_TOKEN without MODEL will cause Claude Code to request claude-opus-4-7 or similar IDs that TokenSG hasn't onboarded, resulting in 404.

See Models for the full list of IDs and pricing.

Verifying the connection ​

Fire a test message in Claude Code:

/doctor

Or just ask Claude anything. Then:

  1. Log into the Console → Request Logs to confirm the request landed
  2. Or watch the Today's Usage card on the Dashboard for credit consumption

A new row in the log = you're connected.

Advanced Configuration ​

Disable non-essential traffic ​

When using a third-party proxy like TokenSG, Claude Code still sends telemetry, auto-update checks, error reports, and feedback surveys to Anthropic's servers. To disable all of these:

json
{
  "env": {
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

Add this to ~/.claude/settings.json alongside the other variables. Claude Code functionality is unaffected — only background traffic is suppressed.

Routing to non-Claude models ​

The ANTHROPIC_DEFAULT_*_MODEL variables accept any model ID your upstream supports, not just Claude models. If TokenSG has onboarded models from other providers (e.g., Gemini, DeepSeek), you can route Claude Code's model tiers to them:

json
{
  "env": {
    "ANTHROPIC_MODEL": "claude-opus-4-6",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "gemini-2.5-pro",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "gemini-2.5-pro",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gemini-2.5-flash"
  }
}

Feature compatibility

Claude Code's advanced features (extended thinking, adaptive reasoning, effort levels) rely on matching model IDs against known Anthropic patterns. When routing to non-Claude models, these features may be unavailable or silently ignored.

Check Models for all available model IDs on TokenSG.

Troubleshooting ​

Connection / TLS errors ​

System proxy interference: If http_proxy / https_proxy are set, they may intercept TokenSG traffic. Exclude the TokenSG domain:

bash
export NO_PROXY="api.tokensg.ai"

Self-signed certificates: In corporate networks with custom CA chains, import them:

bash
export NODE_EXTRA_CA_CERTS=/path/to/your-ca-chain.pem

Switching back to Anthropic ​

Unset ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN (or remove them from settings.json's env field). Claude Code falls back to its default Anthropic authentication.

Auth failures (401 / 403) ​

  • Check key status / expiry on the API Keys page
  • Verify you're using ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY
  • Confirm ANTHROPIC_BASE_URL has no trailing /v1

Insufficient balance ​

TokenSG deducts per-token in real time. When your balance runs out, requests return 402 or insufficient_balance. Top up on the wallet page, or enable auto-topup.