Notice: Kling 4.0 is here: text-to-video and image-to-video are 20% off for a limited time. Try it now
HiAPI
Tutorials
On this page

Claude Code

Import the configuration with CC Switch or set environment variables to use Claude models in Claude Code through HiAPI.

Claude Code can connect to HiAPI through CC Switch or environment variables; CC Switch is recommended because you don’t edit any config file. HiAPI uses the Anthropic Messages protocol, and Claude Code connects to the official Anthropic API by default, so you only need to change two values to switch over. This tutorial was verified on Windows 11 with Claude Code 2.1.284, using claude-opus-5-5 as the example model.

1. Install Claude Code

Install Node.js first (LTS 22.19 or later); if you haven’t, see Node.js setup. Run each line in a terminal:

Terminal
npm install -g @anthropic-ai/claude-code
claude --version

You should see a version number.

CC Switch writes the configuration into Claude Code, so you won’t have to edit files when you change providers later. If you don’t have CC Switch yet, install it following CC Switch install and one-click import.

  1. Open HiAPI Console → API Keys and choose the key to use; if you don’t have one, create one as described in Get an API Key. You don’t need to copy the key here; the import carries it over.

Create a key

  1. Click Import CCS to the right of the key (CCS means CC Switch). The browser opens CC Switch and passes this provider configuration to it.

Import CC Switch button

  1. During the import, choose Claude Code as the tool, then tick the models you want to use.

Choose the tool and model

  1. Check the Base URL, API key and model, then click Import. The page switches to CC Switch and writes the configuration.

Confirm the import configuration

  1. Back in the CC Switch main window, click Switch provider on the HiAPI entry.

Switch provider

  1. Open a new terminal, go to your project directory and run claude.

Claude Code in the terminal

3. Option 2: configure with environment variables

You can skip CC Switch. Claude Code reads two environment variables, ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN. Set the Base URL to https://api.hiapi.ai without /v1; Claude Code appends the path itself. Replace YOUR_HIAPI_API_KEY below with your HiAPI API key and keep the quotes.

We also recommend setting CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to turn off Claude Code’s experimental feature requests, so a third-party endpoint doesn’t reject them with an error. CC Switch writes this setting automatically on import.

Current terminal only

This stops working when you close the window; it is good for a first test before setting it up permanently.

Terminal
export ANTHROPIC_BASE_URL="https://api.hiapi.ai"
export ANTHROPIC_AUTH_TOKEN="YOUR_HIAPI_API_KEY"
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
claude
PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.hiapi.ai"
$env:ANTHROPIC_AUTH_TOKEN = "YOUR_HIAPI_API_KEY"
$env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = "1"
claude
CMD
set "ANTHROPIC_BASE_URL=https://api.hiapi.ai"
set "ANTHROPIC_AUTH_TOKEN=YOUR_HIAPI_API_KEY"
set "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1"
claude

Persist across sessions

Mac uses zsh by default. Append the three lines to ~/.zshrc (use ~/.bashrc for bash), then reload it:

Terminal
echo 'export ANTHROPIC_BASE_URL="https://api.hiapi.ai"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="YOUR_HIAPI_API_KEY"' >> ~/.zshrc
echo 'export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1' >> ~/.zshrc
source ~/.zshrc

On Windows, use setx to write them into your user environment variables; they take effect after you reopen the terminal:

CMD
setx ANTHROPIC_BASE_URL "https://api.hiapi.ai"
setx ANTHROPIC_AUTH_TOKEN "YOUR_HIAPI_API_KEY"
setx CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS "1"

4. Verify

Run claude in your project directory and send “Hello, introduce yourself in one sentence.” If it replies normally and can read project files, the connection works. To double-check, type /status to see the Base URL and model, or open Request logs in the HiAPI console to find this request.

5. Troubleshooting

Only issues specific to Claude Code are listed here. For common errors such as 401, 404 and 429, see Common errors.

ErrorCauseFix
404 / model not availableA /v1 was added to the end of the Base URLSet Claude Code’s Base URL to https://api.hiapi.ai without /v1
The address in /status is not https://api.hiapi.aiYou signed in to an official Anthropic account earlier, or the environment variables did not take effectRun /logout to sign out of the official account first; if you use environment variables, close the terminal, reopen it and run claude again
Auth conflict on startupBoth ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are setRemove ANTHROPIC_API_KEY and keep only ANTHROPIC_AUTH_TOKEN
Still connecting to the official API after the CC Switch importYou did not switch to HiAPI in CC Switch, or the terminal was opened before the switchConfirm HiAPI is switched, then open a new terminal and run claude