Prerequisites
Before you begin, make sure:
Claude Code is installed
Install the Claude Code CLI via npm or pnpm:
# npmnpm install -g @anthropic-ai/claude-code # pnpmpnpm install -g @anthropic-ai/claude-codeOr visit the official Claude Code docs for the latest installation instructions.
You have a MaiToken API key
Sign in to the MaiToken Console to get your API key (it starts with
sk-).
Tip: If you don't have a MaiToken account yet, sign up at MaiToken first and get your API key.
Configuration
Claude Code supports several ways to configure a custom API endpoint, letting you use MaiToken as an alternative backend for the Anthropic API.
Claude Code uses two separate JSON files: the onboarding state and the environment variables must be written to their respective files to take effect.
First, confirm onboarding is complete
Set onboarding as completed in ~/.claude.json in your home directory (create the file if it doesn't exist):
{ "hasCompletedOnboarding": true}This file is only for the CLI state flag; put your API key and base URL in the settings.json below.
Option 1: Configure via settings.json (recommended)
Set the environment variables in ~/.claude/settings.json (global) or .claude/settings.json in your project root (project-level), without touching your shell config files:
{ "env": { "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxxxxxx", "ANTHROPIC_BASE_URL": "https://api.maitoken.com" }}Global configuration (recommended, applies to all projects):
# Create or edit ~/.claude/settings.jsonmkdir -p ~/.claudeThen write the JSON above into ~/.claude/settings.json.
Project-level configuration (applies only to the current project):
Create .claude/settings.json in the project root. Don't put the API Key in a project-level file — keep ANTHROPIC_AUTH_TOKEN in the global config only, and put just ANTHROPIC_BASE_URL in the project config:
{ "env": { "ANTHROPIC_BASE_URL": "https://api.maitoken.com" }}Note: Put
hasCompletedOnboardingin~/.claude.json, andenvin~/.claude/settings.jsonor.claude/settings.json. Don't mix them into the same file.
Option 2: Configure via environment variables
Suitable for one-off use or CI/CD environments.
macOS / Linux
Set temporarily in the terminal (valid for the current session):
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxx"export ANTHROPIC_BASE_URL="https://maitoken.com"claudeFor a permanent setup, add the following to ~/.bashrc or ~/.zshrc:
export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxx"export ANTHROPIC_BASE_URL="https://maitoken.com"Then run:
source ~/.zshrc # or source ~/.bashrcWindows
Set temporarily in PowerShell:
$env:ANTHROPIC_AUTH_TOKEN = "sk-xxxxxxxxxxxx"$env:ANTHROPIC_BASE_URL = "https://maitoken.com"claudePermanent setup (system-level):
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-xxxxxxxxxxxx", "User")[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://maitoken.com", "User")Option 3: Use a .env file
Create a .env file in your project root:
ANTHROPIC_AUTH_TOKEN=sk-xxxxxxxxxxxxANTHROPIC_BASE_URL=https://api.maitoken.comNote: Add .env to .gitignore to avoid leaking your API key.
Configuration Reference
| Setting | Value |
|---|---|
| ANTHROPIC_AUTH_TOKEN | Your MaiToken API key (sk-xxxxxxxxxxxx) |
| ANTHROPIC_BASE_URL | https://api.maitoken.com |
Verify the Configuration
Once configured, run the following to verify the connection works:
claude --versionThen start Claude Code:
claudeIf everything is configured correctly, Claude Code will connect to Claude models through MaiToken and respond normally.
Recommended Models
Through MaiToken you can use the following Claude models:
| Model Name | Model ID | Highlights |
|---|---|---|
| Claude Opus 4.6 | claude-opus-4-6 |
Most powerful, best for complex tasks |
| Claude Sonnet 4.6 | claude-sonnet-4-6 |
Balanced performance and speed; recommended for daily use |
| Claude Haiku 4.5 | claude-haiku-4-5-20251001 |
Fast responses, ideal for simple tasks |
To switch models, use the /model command, or specify one at startup with the --model flag:
claude --model claude-sonnet-4-6FAQ
Q1: Getting Authentication error or 401 Unauthorized?
Solution:
- Check that
ANTHROPIC_AUTH_TOKENis set correctly and starts withsk- - Confirm the key hasn't expired in the MaiToken Console
- Make sure your account balance is sufficient
Q2: Getting Connection refused or can't connect?
Solution:
- Confirm
ANTHROPIC_BASE_URLis set tohttps://api.maitoken.com - Check your network connection and that you can reach
https://api.maitoken.com - If you're in mainland China, you may need to configure a proxy
Q3: How do I check the current environment variable configuration?
echo $ANTHROPIC_AUTH_TOKENecho $ANTHROPIC_BASE_URLQ4: Common Error Codes
| Error Message | Cause | Solution |
|---|---|---|
401 Unauthorized |
API key invalid or expired | Get a new API key |
429 Too Many Requests |
Request rate exceeded | Wait a moment and retry |
500 Internal Server Error |
Temporary server failure | Wait a few minutes and retry |
insufficient_quota |
Insufficient account balance | Top up in the Console |
Tips
1. Quick start inside a project
Enter your project directory and run claude directly — Claude Code automatically reads the project context:
cd /your/projectclaude2. Common Commands
| Command | Description |
|---|---|
/help |
Show help |
/model |
Switch models |
/clear |
Clear the current conversation |
/exit or Ctrl+C |
Exit Claude Code |
3. Working with Code
Claude Code can read and modify project files. Common use cases:
- Code review — have Claude Code review your code and suggest improvements
- Generate code — describe what you need and Claude Code writes it to files directly
- Debug errors — paste an error message and get debugging suggestions
- Refactor code — have Claude Code improve your code structure
Support and Help
If you run into any issues while using MaiToken:
Get started with MaiToken — sign up now, get your API key, and start coding efficiently in Claude Code!
