Claude Code calls the Anthropic API by default. Developers in mainland China often run into unstable access, restricted payment methods, and awkward team quota management, which is why so many of them search for "Claude Code relay."

This article explains what a relay is, what it can and cannot solve, how to choose one, how to configure it, and what risks to watch for.

Note: Claude Code and Anthropic are trademarks of their respective owners. This article is for technical discussion only. Refer to the official documentation and the provider's site for specifics.

1. What a Claude Code relay is

It is not another Claude Code. It is an API gateway layer:

Claude Code → relay gateway (auth / billing / routing) → Anthropic or another compatible model

You still use the Claude Code client; you only change ANTHROPIC_BASE_URL and the key to the gateway's values. From the client's perspective, it is still calling the Anthropic Messages API.

2. What it solves

  • Unstable access from mainland China.
  • Inconvenient payment methods or top-ups.
  • Teams need a unified bill and quota policy.
  • One key can switch between several providers' models.
  • Usage logs and error troubleshooting are available.
  • Limits can be set per member or per project.

3. What it cannot solve

  • It cannot turn a web subscription or membership into API access.
  • It cannot promise uninterrupted availability; upstream incidents still affect you.
  • It cannot replace your own compliance or data assessment.
  • It cannot promise same-day support for every new Claude Code feature.
  • It cannot remove upstream model price changes.

4. How to choose a Claude Code relay

1. Protocol compatibility

It must support the Anthropic Messages API and at least handle:

  • Normal conversation.
  • Streaming output.
  • Tool calls.
  • Long context.
  • Common Claude Code requests.

A relay that only supports the OpenAI protocol may not work directly with Claude Code. Confirm whether it offers an Anthropic-compatible endpoint.

2. Stability

Look at the error rate, P95 latency, rate-limit policy, and whether retries or backup channels exist. Do not judge from a single request.

3. Billing

Check how input, output, and cached tokens are calculated, whether there is a minimum spend, and what the refund rules are. Prices are listed under Model Pricing.

4. Quota management

Can you issue one key per person, set project-level limits, and configure expiry times? These are essential for teams.

5. Logs

Can you see the model, token count, latency, and error for every call? Debugging and cost analysis depend on it.

6. Compliance

Ask whether data is stored, for how long, whether it is used for training, and whether a contract is available. Enterprise buyers need clear answers.

5. Configuration steps

1. Create a key

Register at ZSQH AI Gateway, create a dedicated key for claude-code, and set a spending limit.

2. Configure environment variables

macOS/Linux:

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

Windows PowerShell:

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

Some clients use ANTHROPIC_AUTH_TOKEN instead; replace it according to the client's documentation.

3. Choose a model

Model names are listed under Model Pricing. Inside Claude Code you can switch between Opus, Sonnet, and Haiku depending on the task.

4. Verify

Run claude in a project directory, give it a simple task, and confirm that it can read files, edit code, and run commands normally.

6. Test checklist

  1. Does a normal conversation return a response?
  2. Does streaming output work?
  3. Do tool calls work, including reading files and running commands?
  4. Is long context truncated?
  5. Is concurrency stable at 5 and 10 requests?
  6. Are error codes clear?
  7. Is the bill reasonable?

Observe the service for 3–7 days before deciding whether to use it long term.

7. Risks and pitfalls

1. OpenAI protocol only

Claude Code uses the Anthropic protocol, so confirm compatibility before buying.

2. Key leakage

Do not put keys in code, screenshots, or public repositories. Issue one key per person and set a quota.

3. Low-price traps

Prices that are too low may indicate shared quotas, rate limiting, weak upstream capacity, or hidden restrictions. Start with a small traffic test.

4. Expired model names

Old model names may stop working after upstream upgrades. Watch the pricing page and announcements.

5. Data compliance

Before enterprise use, confirm data retention, training use, contracts, and invoicing.

8. Direct official access vs a relay

Dimension Direct official access Relay gateway
Access Depends on your network Usually better adapted to mainland China
Payment Official methods Top-up on the provider's site
Models Claude only Multiple models
Billing Official dashboard Unified console
Risk Account and payment barriers Risk of choosing the wrong provider

There is no absolute winner. It depends on your network, payment options, team, and compliance requirements.

FAQ

Can a Claude Code relay get my account banned?

That depends on the provider's upstream compliance and how you use the service. Choose a provider with clear terms and stable operations, and follow upstream policies.

Does a relay support every Claude Code feature?

Not necessarily. New features may depend on specific API capabilities. Test them against your own workflow before relying on them.

Can I build one myself?

Yes. Open-source gateways such as New API and One API can be self-hosted, but you need servers, upstream channels, and operations work. See the One API and New API guide.

Next steps

If you need stable Claude Code access from mainland China, sign up for ZSQH AI Gateway, create a small key, and run through the checklist above. For configuration details, see the Claude Code API guide.

Further reading: