Skip to content

Claude Code with the TokenPilot relay

Learn how to configure the TokenPilot relay in the Claude Code CLI for efficient AI-assisted coding.

Live syncGET /v1/models
Click a model name to copy

Models available on TokenPilot

34 models spanning the OpenAI GPT and Anthropic Claude families, all served from https://go.aitokenpilot.com/v1.

OpenAI · GPT

22 models

For OpenAI-protocol clients: Codex, Cursor, Cline, Cherry Studio, and more

Chat & reasoning

General chat, reasoning, long context

o-series (deep reasoning)

Complex reasoning, math, coding

Coding

Codex series — code generation & refactoring

Multimodal (audio / realtime)

Realtime voice, audio in/out

Image generation

Text-to-image, image editing

Anthropic · Claude

12 models

For Anthropic-protocol clients: Claude Code, CC Switch, Hermes, and more

Opus (flagship reasoning)

Top-tier reasoning and coding for complex tasks

Sonnet (balanced workhorse)

Balanced speed and quality — the daily driver

Haiku (lightweight & fast)

Fast, low-cost responses for simple tasks

What is Claude Code

Claude Code is Anthropic's official command-line AI coding assistant. It runs right in your terminal, reads your codebase, runs commands, and edits files — turning what used to be a lot of clicking around in an IDE into a single sentence in the terminal.

Connecting Claude Code to TokenPilot

Claude Code natively supports switching the API endpoint via ANTHROPIC_BASE_URL. Point it at TokenPilot (https://go.aitokenpilot.com) and you can call Claude Sonnet / Opus with a single token, billed by actual token usage.

Who it's for

  • Anyone without a Claude Pro subscription who still wants to code with the Claude Code CLI
  • Teams sharing a quota who need precise per-token billing
  • Users whose access to Anthropic's official endpoint is unstable and who need a relay

Differences from the official service

ItemAnthropic officialTokenPilot
BillingClaude Pro, from $20/monthPay per token used
LimitsSoft message cap every 5 hoursOnly total tokens matter
OnboardingApply for a console API keyOne sk- token covers everything
Access in ChinaNeeds a stable connectionDirect connection

Terminal-native

Interact with the AI right in your terminal — no need to leave the command line

Code-aware

Analyzes your project structure, understands context, answers precisely

Pay as you go

Pay only for the tokens you use — no fixed subscription cost

Direct access in China

Connects directly on most mainland networks, no extra proxy needed

Install Claude Code

Install Claude Code globally with npm:

bash
npm install -g @anthropic-ai/claude-code

INFO

Once installed, run the claude command to launch Claude Code.

Node.js version

Claude Code requires Node.js 18 or 20 LTS or higher. If it's not installed, we recommend a version manager like nvm or fnm.

Configure TokenPilot

Get your API key

Visit the TokenPilot console, sign up, and get your API key. The token looks like sk-xxxx... and is shown only once — copy and save it immediately.

Set environment variables

Set these environment variables in your terminal:

bash
# macOS / Linux
export ANTHROPIC_BASE_URL="https://go.aitokenpilot.com"
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxx"

Important

  • ANTHROPIC_BASE_URL must not include a /v1 suffix — the Anthropic protocol uses the root path
  • Use ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY — TokenPilot uses Bearer auth and reads the former

Verify the configuration

Run Claude Code to confirm the setup worked:

bash
claude --version && claude 'Hello, are you connected?'

Persist to your shell config

The export commands above only apply to the current session. To load them automatically in every new terminal, write them to your shell config file:

bash
# Append to ~/.zshrc (zsh users) or ~/.bashrc (bash users)
echo 'export ANTHROPIC_BASE_URL=https://go.aitokenpilot.com' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN=sk-xxxxxxxxxx' >> ~/.zshrc

# Apply immediately
source ~/.zshrc
powershell
# Current session
$env:ANTHROPIC_BASE_URL = "https://go.aitokenpilot.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-xxxxxxxxxx"

# Persist (user-level environment variables)
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://go.aitokenpilot.com", "User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-xxxxxxxxxx", "User")

Security note

A token is the same as a password — don't put it in code, don't commit it to Git, don't paste it in chat groups. If you suspect it's leaked, revoke and recreate it in the console right away.

Double-check that the environment variables took effect:

bash
echo $ANTHROPIC_BASE_URL
# Should output: https://go.aitokenpilot.com

echo $ANTHROPIC_AUTH_TOKEN
# Should output: sk-xxxx... (the first few characters)

Basic usage

Start an interactive session

Launch from your project root so Claude reads the current directory as context:

bash
cd ~/your-project
claude

Then just ask:

> Convert the synchronous calls in services/billing.ts to run concurrently
> This OpenAI-compatible request is missing the Authorization header — add it
> Write a unit test for utils/rate-limiter.ts

One-off question

Ask a single question without entering an interactive session:

bash
claude "This regex doesn't match emails with hyphens — fix it for me"

Analyze the current directory

bash
claude -p . 'Walk me through the auth flow of this project'

Specify a model

Set a default model via the ANTHROPIC_MODEL environment variable:

bash
# Sonnet 4.6 — recommended for daily development, strong at coding
export ANTHROPIC_MODEL=claude-sonnet-4-6

# Opus 4.7 — strongest reasoning, for complex tasks
export ANTHROPIC_MODEL=claude-opus-4-7

# Haiku 4.5 — millisecond responses, 10x cheaper
export ANTHROPIC_MODEL=claude-haiku-4-5-20251001

You can also override it for a single call with --model:

bash
claude --model claude-opus-4-7 'Design a request-retry component with exponential backoff'

Or switch within a session using /model.

Common in-session commands

CommandDescription
/helpShow available commands
/clearClear the current conversation context
/compactCompress the session history, keeping the key points to save tokens
/modelView or switch the current model
/costShow the token usage of this session
/exitLeave the session

Best practices

Pick a model by scenario

ScenarioRecommended modelWhy
Everyday code generationclaude-sonnet-4-6High code quality, good speed
Architecture design, complex refactorsclaude-opus-4-7Deepest reasoning
Simple Q&A, commit messagesclaude-haiku-4-5-2025100110x cheaper, fast
Large-codebase analysisclaude-sonnet-4-6200K context + great value

Control token usage

  • When the context gets full, prefer /compact to compress the history (keeps the key points); to switch topics entirely, use /clear
  • For simple tasks (comments, commit messages) switch to Haiku
  • Run /cost before ending a session to check usage and adjust in time
  • Add .claude/ to .gitignore so the cache doesn't get committed

Monitor usage with claude-hud

claude-hud is a community Claude Code plugin that shows your token / context usage for the current session in the status bar in real time, and reminds you to /compact or /clear when you cross a threshold — more reliable than doing the math in your head.

bash
# Run inside a claude session
/plugin marketplace add jarrodwatts/claude-hud
/plugin install claude-hud
/reload-plugins
/claude-hud:setup

After installing, run /claude-hud:setup once to choose what the status line shows (usage / remaining / model / a custom note). Restart claude and you'll have a usage bar pinned to the status line.

Project-level configuration

Create a CLAUDE.md in your project root with your project conventions, and Claude Code loads it automatically:

markdown
# CLAUDE.md

## Tech stack
- Frontend: Vue 3 + Vite + TypeScript + Tailwind CSS
- Backend: Go 1.22 + Gin + sqlc
- Database: PostgreSQL, cache Redis

## Code style
- Go: wrap errors instead of re-formatting with `fmt.Errorf` repeatedly; shared packages don't import business models
- Frontend: Composition API + `<script setup>`, global state via Pinia
- Naming: Vue components PascalCase, composables prefixed with `use-`

## Testing
- Go: `go test ./...`, table-driven style
- Frontend: Vitest, `*.test.ts` alongside the source file

Make it your own

The above is an example. Replace it with your project's real conventions — style, naming, layout, testing — and Claude Code will read it on every session, saving you from repeating yourself.

Veteran tips

  • Run Claude Code from the project root so it understands the full project context
  • Use the -p flag to point at a specific file or directory to analyze
  • Pair it with Git and let Claude help review your code changes

FAQ

Q: Error 401 / Authentication failed

The API key is invalid or not loaded. First confirm the variable is loaded correctly, then self-test with curl:

bash
# Confirm the env var is loaded (should output sk-xxxx...)
echo $ANTHROPIC_AUTH_TOKEN

# curl self-test — 200 means it works, 401 means a token problem
curl https://go.aitokenpilot.com/v1/messages \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-6","max_tokens":50,"messages":[{"role":"user","content":"hi"}]}'

Common causes: a stray space when copying the token; using ANTHROPIC_API_KEY instead of ANTHROPIC_AUTH_TOKEN; or a /v1 suffix on the base URL.

Q: Error connection timeout

The network is unreachable. Test connectivity first, then check whether a corporate/school proxy is blocking it:

bash
# Test connectivity
curl -I https://go.aitokenpilot.com

# Route through a local HTTP proxy (change the port to match yours)
export HTTPS_PROXY=http://127.0.0.1:7890
claude

Q: Insufficient balance / quota exceeded

Sign in to the TokenPilot console and top up on the "Account balance" page; the "Usage statistics" page shows a detailed breakdown of consumption per model.

Q: How do I switch models?

Use the --model flag for a one-off, e.g. claude --model claude-opus-4-7; or switch within a session with the /model command.