TokenDNS LogoTokenDNS

Using with Claude Code

Claude Code is Anthropic's agentic coding tool for the terminal. It understands your project context and turns natural-language requests into real code changes, debugging, test runs and maintenance work. It works directly in your project directory and fits into an existing command-line workflow.

Before you start

  1. Create a usable token on the API keys page.
  2. Make sure the token's group can call the Claude models you want.
  3. Never commit a real token into a repository, a screenshot or a chat log.

The path is: create a token → configure Claude Code → send one short test message → check the request in the usage logs.

Install Claude Code

On macOS, Linux or WSL the official native installer is recommended:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

Homebrew and WinGet also work:

brew install --cask claude-code
winget install Anthropic.ClaudeCode

Temporary configuration

Set the environment variables in your current terminal:

export ANTHROPIC_BASE_URL="https://api.tokendns.net"
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
export ANTHROPIC_MODEL="claude-sonnet-4-6"

Then enter your project directory and run:

claude

Do not append /v1 to ANTHROPIC_BASE_URL; Claude Code requests /v1/messages itself. ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer ..., which is what gateways like TokenDNS expect.

Persistent configuration

Non-sensitive settings can live in ~/.claude/settings.json, with the token injected from your shell environment:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.tokendns.net",
    "ANTHROPIC_MODEL": "claude-sonnet-4-6",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}

CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 makes recent versions of Claude Code fetch the available models from the gateway's /v1/models. Whether a particular model shows up still depends on the token's group and the platform's current catalogue.

Verify and troubleshoot

After starting, run /status and /model to confirm that requests go to the TokenDNS endpoint with the model you expect. Common issues:

  • 401: check that ANTHROPIC_AUTH_TOKEN is set in the same terminal that launched Claude Code.
  • 404 or a duplicated path segment: make sure the base URL is https://api.tokendns.net with no /v1.
  • Model unavailable: check the model ID and token group on the model list, or enable gateway model discovery.
  • Still routed through the gateway after signing in to an official subscription: this is expected. ANTHROPIC_AUTH_TOKEN takes precedence over subscription OAuth; unset the corresponding environment variables to stop using the gateway.

Tip: you can also import the configuration from the API keys page through CC-Switch. Either way, verify the effective authentication method and model with /status.

On this page