Skip to main content
Claude Code can connect to HaiToken in two ways: configure it through CC Switch, or configure the Claude Code CLI directly with environment variables. Both methods use HaiToken’s Anthropic Messages protocol.

Protocol and endpoint

Claude Code uses the Anthropic Messages protocol. In CC Switch, select Anthropic Messages (Native) and set the endpoint to https://api.haitoken.ai. CC Switch then sends requests to HaiToken’s POST /v1/messages endpoint.
Enter only https://api.haitoken.ai in the API Endpoint field. Do not append /v1 or /v1/messages.

What you need

  • Claude Code installed
  • A HaiToken API key
  • At least one model ID available to your API key
  • CC Switch installed if you use the CC Switch method

Step 1: Select Claude Code and add a provider

Open CC Switch, select the Claude Code / Claude Official app from the app bar, then click the + button in the upper-right corner to add a provider.

Step 2: Choose Custom Config and enter the API key

On the Claude Provider tab:
  1. Choose Custom Config.
  2. Optionally name the provider, for example HaiToken.
  3. Paste your HaiToken API key into API Key.

Step 3: Complete the provider configuration

Scroll to the remaining fields and enter the following values: Click Fetch Models after entering the API key and endpoint. CC Switch should confirm that it found the models available to your key.

Step 4: Map the Claude roles to HaiToken models

In Model Mapping, choose the model to use for each Claude role that you need:
  • Sonnet is the usual main coding model.
  • Opus, Haiku, and the other roles are optional.
  • Use a model ID returned by HaiToken. The requested-model value must match that model ID exactly.
The Auth Field is an environment-variable name used by Claude Code, not your API key. Leave ANTHROPIC_AUTH_TOKEN unchanged; your actual key stays in the API Key field.

Step 5: Save and test

Click Add, make sure the new provider is active for Claude Code, then start or restart Claude Code and send a simple request such as hello. If a response is returned, Claude Code is using your HaiToken provider through CC Switch.

Method 2: Configure the Claude Code CLI directly

Use this method when you want to connect Claude Code without CC Switch. Set the variables in the terminal from which you launch Claude Code.

Step 1: Set the API key, endpoint, and default model

Windows PowerShell:
macOS / Linux:
Replace claude-sonnet-4-0 with an actual model ID available to your API key. Do not append /v1 or /v1/messages to ANTHROPIC_BASE_URL.

Step 2: Choose or switch the model

You can set a default with ANTHROPIC_MODEL, start one session with a specific model, or switch while Claude Code is running:
Inside Claude Code, use:
The in-session /model command takes effect immediately. The --model flag applies only to that launch and overrides ANTHROPIC_MODEL for the session.

Step 3: Persist the configuration if needed

The commands above apply only to the current terminal session. To reuse the setup, add the same environment variables to your PowerShell profile on Windows, ~/.zshrc on macOS or zsh-based Linux shells, or ~/.bashrc on bash-based Linux shells. Open a new terminal after saving the profile, then run claude.

Step 4: Verify the direct CLI connection

Start Claude Code from the terminal where the variables are set and send a simple request such as hello. A normal response confirms that Claude Code is using HaiToken.

Verification checklist

  1. CC Switch shows the provider as active for Claude Code.
  2. Fetch Models succeeds and returns models available to your API key.
  3. The API Endpoint is https://api.haitoken.ai without a trailing slash or path.
  4. API Format is Anthropic Messages (Native).
  5. Claude Code returns a normal response after it is restarted.

FAQ

Next