Claude Code is a command-line coding tool from Anthropic. It is designed for reading code, editing code, running tests, and refactoring in the terminal. It calls Anthropic's API by default, so developers in China often face three problems: unstable access to the official endpoint, restricted payment methods, and team quotas and costs that are hard to manage.

ZSQH AI Gateway provides a unified API entry point: you only need one API Key to call Claude and other mainstream models through a compatible interface. This article walks through the full process, from registration and key creation to Base URL configuration and the first run.

Note: Claude Code updates frequently, and environment variables and menu names may change between versions. This article uses common versions as of October 2026; refer to claude --help and the official documentation for specifics.

1. First, understand which interface Claude Code uses

Claude Code uses the Anthropic Messages API by default, not OpenAI's Chat Completions API. When connecting to a third-party gateway, prepare three things:

  1. Base URL: the endpoint address, for example https://ai.zhongshangqihang.com.
  2. API Key: a token created in the ZSQH console, usually starting with sk-.
  3. Model name: for example claude-sonnet-4-5 or claude-opus-4-1; use the model names currently shown on the site's pricing page.

If you use the OpenAI SDK or another OpenAI-compatible tool, the Base URL usually needs https://ai.zhongshangqihang.com/v1. When Claude Code uses the Anthropic protocol, enter the root address and let the client append /v1/messages itself.

2. Prepare an account and API Key

1. Register and sign in

Open the ZSQH AI Gateway, register an account, and sign in to the console.

2. Create an API Key

Go to the "API Keys" page in the console and create a new key. Recommendations:

  • Give it a clear name, for example claude-code-work-laptop.
  • Set a spending limit so a leaked key cannot be used heavily.
  • Set an expiration time so it stops working when unused for a long period.
  • Copy and save it immediately after creation; the key is usually shown in full only once.

3. Confirm your balance

Check the balance on the "Wallet" or "Top-up" page. Different models are billed differently; see model pricing for specific rates.

3. Configure Claude Code

Option A: macOS / Linux environment variables

Run in the terminal:

export ANTHROPIC_BASE_URL="https://ai.zhongshangqihang.com"
export ANTHROPIC_API_KEY="sk-your-key"
claude

To make this apply every time you open a terminal, add the two lines to ~/.zshrc or ~/.bashrc, then run source ~/.zshrc.

Option B: Windows PowerShell

$env:ANTHROPIC_BASE_URL="https://ai.zhongshangqihang.com"
$env:ANTHROPIC_API_KEY="sk-your-key"
claude

Option C: When the client requires AUTH_TOKEN

Some third-party clients or proxy configurations use ANTHROPIC_AUTH_TOKEN instead of ANTHROPIC_API_KEY:

export ANTHROPIC_BASE_URL="https://ai.zhongshangqihang.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-key"

If both variables exist, keep only the one required by the client documentation to avoid authentication header conflicts. Different Claude Code versions support these variable names slightly differently; if you see a 401, check this first.

Option D: Project-level configuration

If you do not want to change the global environment, inject environment variables with a .env file or a startup script in the project directory. Do not commit .env to Git:

# .env.local (do not commit)
ANTHROPIC_BASE_URL=https://ai.zhongshangqihang.com
ANTHROPIC_API_KEY=sk-your-key

Then load the file before starting Claude Code. Loading methods differ between shells; follow your project's conventions.

4. Choose a model

The Claude family usually comes in three tiers: Opus, Sonnet, and Haiku.

Tier Best for Characteristics
Opus Complex refactoring, long-chain agents, hard reasoning Highest capability, usually the highest unit price
Sonnet Daily coding, bug fixes, code review A balance of capability and cost
Haiku Simple completion, batch jobs, low-cost calls Fast, usually a lower unit price

In Claude Code you can specify the model through a model parameter or an environment variable. For the actual available model names, refer to the model pricing page; a nonexistent model name usually returns model not found.

5. First call and troubleshooting

After configuration, run this in your project directory:

claude

Then enter a simple task, such as "explain the directory structure of this project." If you get a normal response, the Base URL, key, and model are all working.

Common errors:

Error Likely cause What to do
401 Unauthorized Wrong or expired key, or wrong variable name Copy the key again; check ANTHROPIC_API_KEY / ANTHROPIC_AUTH_TOKEN
404 Not Found Extra or missing /v1 in the Base URL Claude Code uses the root address; the OpenAI SDK uses /v1
model not found Model name does not exist or is not enabled Copy the current model name from the pricing page
429 Too Many Requests Concurrency or rate limit exceeded Reduce concurrency and retry later; check the key quota
insufficient quota Insufficient balance Top up and retry
Stuck or timing out Network or proxy issue Check the network, DNS, and proxy settings

6. How to control cost and quota

Claude Code costs come mainly from input tokens, output tokens, long context, and caching. To control cost:

  1. Create a separate key for each project, with a quota and expiration time.
  2. Use Sonnet/Haiku for simple tasks and switch to Opus only for complex work.
  3. Avoid stuffing an entire large repository into context at once; let Claude Code read the relevant files first.
  4. Review usage logs regularly to find the projects and models that consume the most.
  5. Use a unified gateway for teams to manage members, keys, quotas, and bills separately.

For specific rates and billing rules, refer to model pricing. Prices change with model versions and upstream policies; this article does not hardcode numbers to avoid going stale.

7. Security recommendations

  • Do not put API keys in code, screenshots, Git repositories, or public documentation.
  • Set spending limits and expiration times on keys.
  • If you suspect a leak, delete the old key immediately and create a new one.
  • One key per person on a team makes auditing and disabling easier.
  • Use separate keys for production and test environments.

FAQ

Are Claude Code and the Claude API the same thing?

No. Claude Code is a coding tool; the Claude API is a model interface. Claude Code calls models through the API, and you can also use the Claude API to build your own application.

Can a ZSQH key be used directly in Claude Code?

Yes, provided the client uses the Anthropic-compatible protocol and the Base URL, key, and model name are configured correctly. Refer to the on-site integration notes and your current client version for specifics.

Why use a gateway instead of a direct official connection?

The value of a gateway is mainly a unified entry point, unified billing, quota management, auditable usage, and multi-model switching. For teams and access from China, it is usually easier to manage than having each member apply for an official account separately.

Do I need Node.js?

Claude Code is usually installed through npm and requires a Node.js environment. Refer to the official documentation for installation instructions.

Next steps

If you do not have an account yet, register for the ZSQH AI Gateway, create a test key, and configure it as described above to run your first task. If you run into model name or billing issues, check model pricing first, then use the console's usage logs to troubleshoot.

Related reading: