Claude API is well suited to long documents, code, agents, and complex reasoning, but developers in mainland China often hit network instability, payment friction, and quota-management problems when connecting directly. A Claude API relay is a gateway layer that sits between your application and Anthropic to solve exactly that. It does not replace Claude Code or the Claude API; it changes the endpoint your tools talk to, and it takes over authentication, billing, and routing along the way.
This article explains what a relay is, how to choose one, how to connect it, and which risks to check before you commit.
Note: Claude and Anthropic are trademarks of their respective owners. This article is for technical discussion only. Pricing and endpoints are subject to the official documentation and the provider's site.
1. What a Claude API relay is
Your app → relay gateway (auth / billing / routing) → Anthropic Claude
You still call Claude models. You only replace the Base URL and key with the gateway's. From your application's point of view, the request and response format stays the same. Behind the scenes, the gateway authenticates each request, records token usage for billing, writes logs for troubleshooting, and switches to another upstream channel when one becomes unhealthy.
2. What it solves
- Unstable access from mainland China, where direct connections can be slow or intermittent.
- Inconvenient official payment methods, especially for teams without an overseas card or billing entity.
- Teams need a unified bill, member management, and quotas across projects.
- You need Claude, GPT, Gemini, and other models behind one entry point instead of maintaining separate integrations.
- You need usage logs and error troubleshooting when something fails in production.
3. How to choose one
| Criterion | What to confirm |
|---|---|
| Protocol | Does it support the Anthropic Messages API? Does it also offer OpenAI compatibility? |
| Models | Are Opus, Sonnet, and Haiku all available, and are the versions current? |
| Stability | Error rate, P95 latency, rate limiting, and retries. |
| Billing | How input, output, and cached tokens are priced, and whether there are hidden fees. |
| Quotas | Limits per member, key, and project. |
| Logs | Can you inspect tokens, latency, and errors for every call? |
| Compliance | Data retention, contracts, and invoicing. |
4. Configuration
For Claude Code
export ANTHROPIC_BASE_URL="https://ai.zhongshangqihang.com"
export ANTHROPIC_API_KEY="sk-your-key"
claude
For the OpenAI SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-your-key",
base_url="https://ai.zhongshangqihang.com/v1",
)
resp = client.chat.completions.create(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Reply with OK only"}],
)
print(resp.choices[0].message.content)
Note that the Anthropic native protocol and the OpenAI-compatible protocol use different paths and request headers. Configure according to the tool you use.
5. Test checklist
- A normal request and streaming output.
- Tool calls and structured output.
- Whether long context is truncated.
- Success rate at 5 and 10 concurrent requests.
- Whether error codes are clear.
- Whether the bill matches expectations.
6. Risks and pitfalls
- A relay that only supports the OpenAI protocol may not work with Claude Code.
- Prices that look unusually low can mean shared quotas, rate limits, or hidden restrictions.
- Model names change as upstream versions are upgraded; watch the pricing page.
- Before enterprise use, confirm the data terms and invoicing.
- Never put a key in frontend code or a public repository.
FAQ
Is a Claude API relay the same as a Claude Code relay?
Both sit on top of the Claude API, but they are configured for different clients. Claude Code requires Anthropic-protocol compatibility, while ordinary applications can use the OpenAI SDK.
Does a relay affect model quality?
It usually does not change the upstream model, but channel versions, parameter support, and rate limits can differ. Compare results on a fixed test set before migrating.
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 ongoing operations work. See the One API and New API guide.
Next steps
If you need stable access from mainland China or a single entry point for multiple models, sign up for ZSQH AI Gateway and run a small test key first. Model names and prices are listed under Model Pricing.
Further reading:
