Claude Code Configuration Guide

Use MaiToken as the API backend in Claude Code

Prerequisites

Before you begin, make sure that:

  1. Claude Code is installed

    Install the Claude Code CLI using npm or pnpm:

    # npmnpm install -g @anthropic-ai/claude-code # pnpmpnpm install -g @anthropic-ai/claude-code

    Or visit the official Claude Code documentation for the latest installation instructions.

  2. You have obtained a MaiToken API key

    Log in to the MaiToken console to obtain your API key, which starts with sk-.

Tip: If you do not have a MaiToken account yet, register at MaiToken and obtain an API key first.

Configuration Methods

Claude Code supports multiple ways to configure a custom API endpoint, allowing you to use MaiToken as an alternative backend for the Anthropic API.

Claude Code uses two different JSON files: onboarding status and environment variables must be written to their respective files to take effect.

First, Confirm That Onboarding Is Complete

Set onboarding as completed in ~/.claude.json in your home directory. You can create the file if it does not exist:

{  "hasCompletedOnboarding": true}

This file is used only for the CLI status flag. Write the API key and base URL in the settings.json file below.

Configure environment variables in ~/.claude/settings.json (global) or .claude/settings.json in the project root (project-level), without modifying shell configuration files:

{  "env": {    "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxxxxxx",    "ANTHROPIC_BASE_URL": "https://api.maitoken.net"  }}

Global configuration (recommended; applies to all projects):

# Create or edit ~/.claude/settings.jsonmkdir -p ~/.claude

Then write the JSON above to ~/.claude/settings.json.

Project-level configuration (applies only to the current project):

Create .claude/settings.json in the project root. Do not include the API key in the project-level file. It is recommended to define ANTHROPIC_AUTH_TOKEN only in the global configuration and ANTHROPIC_BASE_URL only in the project configuration:

{  "env": {    "ANTHROPIC_BASE_URL": "https://api.maitoken.net"  }}

Note: Put hasCompletedOnboarding in ~/.claude.json and env in ~/.claude/settings.json or .claude/settings.json. Do not combine them in the same file.

Method 2: Configure Through Environment Variables

Suitable for temporary use or CI/CD environments.

macOS / Linux

Set the variables temporarily in the terminal. They are effective only for the current session:

export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxx"export ANTHROPIC_BASE_URL="https://maitoken.com"claude

For permanent configuration, add the following lines to ~/.bashrc or ~/.zshrc:

export ANTHROPIC_AUTH_TOKEN="sk-xxxxxxxxxxxx"export ANTHROPIC_BASE_URL="https://maitoken.com"

Then run:

source ~/.zshrc  # or source ~/.bashrc

Windows

Set the variables temporarily in PowerShell:

$env:ANTHROPIC_AUTH_TOKEN = "sk-xxxxxxxxxxxx"$env:ANTHROPIC_BASE_URL = "https://maitoken.com"claude

Permanent configuration (system-level):

[System.Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-xxxxxxxxxxxx", "User")[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "sk-xxxxxxxxxxxx", "User")

Method 3: Use a .env File

Create a .env file in your project's root directory:

ANTHROPIC_AUTH_TOKEN=sk-xxxxxxxxxxxxANTHROPIC_BASE_URL=https://api.maitoken.net

Note: Add .env to .gitignore to prevent exposing your API key.

Configuration Details

Configuration Item Value
ANTHROPIC_AUTH_TOKEN Your MaiToken API key (sk-xxxxxxxxxxxx)
ANTHROPIC_BASE_URL https://api.maitoken.net

Verify the Configuration

After completing the configuration, run the following command to verify that the connection is working:

claude --version

Then start Claude Code:

claude

If the configuration is correct, Claude Code will connect to Claude models through MaiToken and respond normally.

You can use the following Claude models through MaiToken:

Model Name Model ID Features
Claude Opus 4.6 claude-opus-4-6 Most powerful; suitable for complex tasks
Claude Sonnet 4.6 claude-sonnet-4-6 Balanced performance and speed; recommended for everyday use
Claude Haiku 4.5 claude-haiku-4-5-20251001 Fast responses; suitable for simple tasks

To switch models, use the /model command or specify one at startup with the --model parameter:

claude --model claude-sonnet-4-6

Frequently Asked Questions

Q1: Getting an Authentication error or 401 Unauthorized?

Solution:

  1. Check whether ANTHROPIC_AUTH_TOKEN is set correctly and confirm that it starts with sk-
  2. Verify in the MaiToken Console that the key has not expired
  3. Confirm that your account has sufficient balance

Q2: Getting Connection refused or unable to connect?

Solution:

  1. Confirm that ANTHROPIC_BASE_URL is set to https://api.maitoken.net
  2. Check your network connection and ensure that https://api.maitoken.net is accessible
  3. If you are in mainland China, you may need to configure a proxy

Q3: How do I view the current environment variable configuration?

echo $ANTHROPIC_AUTH_TOKENecho $ANTHROPIC_BASE_URL

Q4: Common Error Codes

Error Message Cause Solution
401 Unauthorized Invalid or expired API key Obtain a new API key
429 Too Many Requests Request rate limit exceeded Wait briefly and try again
500 Internal Server Error Temporary server issue Wait a few minutes and retry
insufficient_quota Insufficient account balance Add funds through the console

Usage Tips

1. Quickly Start Within a Project

Navigate to the project directory and run claude. Claude Code will automatically read the project context:

cd /your/projectclaude

2. Common Commands

Command Description
/help View help information
/model Switch models
/clear Clear the current conversation
/exit or Ctrl+C Exit Claude Code

3. Collaborate on Code

Claude Code can read and modify project files. Common use cases include:

  • Code review - Ask Claude Code to review your code and suggest improvements
  • Code generation - Describe your requirements, and Claude Code will generate code and write it directly to files
  • Error debugging - Paste error messages to receive debugging suggestions
  • Code refactoring - Ask Claude Code to optimize your code structure

Support and Help

If you encounter any issues while using the service:


Get Started with MaiToken — Sign up for MaiToken now, get your API key, and begin an efficient coding journey with Claude Code!