Skip to main content
This guide shows how to configure Claude Code CLI to use AiToEarn’s Anthropic compatible endpoint. After setup, you can call language models available on AiToEarn from your terminal through Claude Code.
If you do not have an API Key yet, read Get API Key. To confirm available model names, check Chat models.
AiToEarn uses ANTHROPIC_API_KEY, not ANTHROPIC_AUTH_TOKEN. If you are adapting another third-party guide, make sure the authentication variable is ANTHROPIC_API_KEY.

What Is Claude Code?

Claude Code is Anthropic’s official command-line interface tool. It brings an AI assistant into your terminal and coding workflow. By configuring AiToEarn’s Anthropic compatible endpoint, you can keep the Claude Code workflow while sending requests through your AiToEarn API Key.

Prerequisites

Before you start, make sure you have:
  1. An AiToEarn account.
  2. AiToEarn API Key.
  3. Access to Terminal, PowerShell, or Command Prompt.

Choose a Base URL

AiToEarn API Keys are bound to the site where they were created. ANTHROPIC_BASE_URL must match the site of your API Key. Do not append /v1/messages to ANTHROPIC_BASE_URL. Claude Code sends Anthropic Messages style requests, which will be routed to AiToEarn’s Anthropic messages endpoint.

Install

Choose the instructions for your operating system.

macOS and Linux

Open Terminal and run:
Verify the installation:

Windows

Open PowerShell as administrator, then run:
If the claude command is not found after installation, add Claude Code to your PATH:
  1. Press Win + X and choose System.
  2. Click Advanced system settings.
  3. Click Environment Variables.
  4. Under System variables, select Path and click Edit.
  5. Click New and add C:\Users\YourUsername\.claude\bin.
  6. Click OK to save.
Restart your terminal and verify:

Configure Environment Variables

Claude Code reads two environment variables:
  • ANTHROPIC_API_KEY: your AiToEarn API Key.
  • ANTHROPIC_BASE_URL: AiToEarn’s Anthropic compatible base URL, selected by site.

macOS and Linux

If you use Zsh, add these lines to ~/.zshrc:
If you use an international API Key, change the second line to:
Apply the changes:
If you use Bash, add the same lines to ~/.bashrc or ~/.bash_profile, then run the matching source command.

Windows PowerShell

China site:
International site:
Restart your terminal after setting the variables.

Windows Command Prompt

China site:
International site:
Restart your terminal after setting the variables.

Method 2: Temporary Configuration

Temporary configuration only applies to the current terminal session. It is useful for quick testing. macOS and Linux:
Windows PowerShell:
Windows Command Prompt:
International site users should change ANTHROPIC_BASE_URL to https://aitoearn.ai/api/ai.

Method 3: Claude Code Settings File

Create or edit ~/.claude/settings.json:
International site users should change ANTHROPIC_BASE_URL to https://aitoearn.ai/api/ai.

Method 4: CC Switch

If you use CC Switch to manage multiple Claude Code providers, add an AiToEarn provider: Save and enable the provider, then start Claude Code to test.

Verify the Setup

After starting Claude Code, enter:
If Anthropic base URL points to your AiToEarn URL, the base configuration is active. You can also send a test message:
Check environment variables: macOS and Linux:
Windows PowerShell:

Troubleshooting

Invalid API Key

  • Confirm the key comes from AiToEarn API Key.
  • Make sure you are not using ANTHROPIC_AUTH_TOKEN as the authentication variable.
  • Check for leading or trailing spaces in the API Key.
  • Confirm the API Key site matches ANTHROPIC_BASE_URL.

Connection Failed

  • Confirm your network can access the site you selected.
  • China site uses https://aitoearn.cn/api/ai.
  • International site uses https://aitoearn.ai/api/ai.
  • Do not set ANTHROPIC_BASE_URL to /api/ai/v1/messages.

Claude Code Not Found

macOS and Linux:
If it is not found, make sure ~/.claude/bin is in PATH. Windows: Confirm PATH includes:
Restart your terminal and run claude --version again.