How to Use the Claude API from China (2026): Three Options Compared
On this page
Short answer: Anthropic does not serve mainland China, Hong Kong or Macau directly, so developers there use one of three routes: an official account in a supported region, Claude on a cloud platform outside China, or a third-party API service that bills in yuan. The third is the quickest — you change the base URL and the key.
This page compares the three, then shows the third-party route step by step with code we ran on November 1, 2026 against api.foo using a test key (the server answered 401 无效的令牌 — "invalid token" — which proves the URL, path and request format are right without spending money). For Claude prices, see Claude API pricing.
The three options at a glance
| Official Claude Console | Cloud platform (AWS Bedrock, Google Vertex AI, Microsoft Foundry) | Third-party API service (e.g. api.foo) | |
|---|---|---|---|
| Account | Must be in a supported region; mainland China, Hong Kong and Macau are not listed | Cloud account in a region that offers Claude; available models follow each cloud's catalog | The provider's own account, usually just an email |
| Payment | Prepaid by card, in USD | Your cloud bill, in USD | Depends on the provider; services aimed at China usually take Alipay and WeChat Pay, in CNY |
| Code changes | None — the official SDK points there by default | Platform client (AnthropicBedrock, AnthropicVertex, AnthropicFoundry) and cloud credentials |
Change base_url and the key; same request format |
| Models and features | Everything, first | Main models; a few features missing (for example, Foundry has no Message Batches API) | Whatever the provider forwards — test caching, thinking and tool use |
| Best for | Teams with a company or billing in a supported region | Companies already on AWS, Google Cloud or Azure | Individual developers and small teams who want to pay in yuan |
Whichever route you pick, your prompts leave your machine and go to that provider. Read its privacy terms before sending sensitive data, and follow the rules that apply where you operate.
Option 1: the official Claude Console
Sign up at platform.claude.com, add a card under Settings → Billing, buy credits, then create a key under Settings → API keys. Keys start with sk-ant- and are shown once. The full walkthrough, including spend limits and the 429 you get at the monthly cap, is in How to get a Claude API key.
This only works if you, or your company, are in a supported region with a card that the Console accepts.
Option 2: Claude on a cloud platform
Anthropic's models are also sold through AWS Bedrock, Google Vertex AI and Microsoft Foundry. You pay through the cloud bill and authenticate with cloud credentials instead of an Anthropic key. Anthropic's SDKs ship a client for each platform, so the request body stays the same while the client class and credentials change.
The catch is setup: you need a cloud account in a region where Claude is offered, model access must be enabled, and some features lag behind the direct API. It makes sense when your company already runs there.
Option 3: a third-party API service, step by step
A third-party API service (often called an API relay or gateway in China) gives you its own key and forwards your requests to the model. With the official SDK, only the address and the key change. Using api.foo as the example:
- Sign up and top up. Create an account at api.foo and top up in Console → Wallet with Alipay, WeChat Pay, a card or USDT. Balances are in yuan; per-model prices are on the Models page.
- Create a key. In Console → API Keys, click Create API Key and copy the key (it starts with
sk-). Check that it can use Claude models. - Point your code at the service. Store the key in an environment variable —
export APIFOO_API_KEY="sk-..."on macOS / Linux, orsetx APIFOO_API_KEY "sk-..."on Windows (then open a new terminal) — and set the base URL.
With the anthropic SDK (pip install anthropic), stop the base URL at the domain — the SDK adds /v1/messages itself:
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["APIFOO_API_KEY"],
base_url="https://api.foo",
)
msg = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Introduce yourself in one sentence."}],
)
print(msg.content[0].text)
If your code already uses the OpenAI SDK, keep it and add /v1:
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["APIFOO_API_KEY"], base_url="https://api.foo/v1")
resp = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Introduce yourself in one sentence."}],
)
print(resp.choices[0].message.content)
Prefer the native anthropic SDK for anything that uses prompt caching, extended thinking, PDFs or images — those features are most complete on the Messages API.
To check the setup without spending anything, send one request with a deliberately wrong key. Both snippets above returned AuthenticationError ... 401 ... 无效的令牌 in our test: the request reached the right endpoint and was rejected only because of the key. A 404 or a connection error instead means the address is wrong.
Using Claude Code rather than your own code? See Claude Code with a custom API.
Four things to test before you commit to a provider
Claude has a few features that providers get wrong more often than others. Top up a small amount and check:
- Prompt caching works. Add
"cache_control": {"type": "ephemeral"}to a long request, send it twice, and look for a non-zerocache_read_input_tokensin the second response'susage. If it stays 0, long conversations will cost several times more. - Official model names work.
claude-sonnet-5-5andclaude-opus-5-5should be accepted as-is. Claude Code sends these names, so this matters if you use it. - Long prompts are billed the way Anthropic bills them. Haiku 5.5 costs five times more above 100k input tokens on the official price list; see whether the provider follows that rule or uses its own.
- Thinking, tool use, images and PDFs work on the native
/v1/messagesendpoint.
For a general checklist (refund rules, who runs the service, uptime), see OpenAI API alternatives.
What to avoid
- Resold official keys. An
sk-ant-key sold by an individual belongs to someone else's account. It can be shared, stolen or revoked at any moment, and your prompts pass through a stranger. - Providers that hide who runs them. Look for terms of service, a privacy policy, a support contact and a refund rule before you top up.
- Large top-ups on day one. Start small and scale up once the four checks above pass.
Errors you may see
| Error | Meaning | Fix |
|---|---|---|
401 无效的令牌 ("invalid token", or Invalid token in English) |
The key is wrong, disabled, expired or out of quota | Copy the whole key again with no spaces; check its status in the console |
用户额度不足 ("insufficient balance") |
Your balance can't cover the request | Top up |
无可用渠道 ("no available channel") |
The key's group doesn't include this model | Check which groups the model is in on the Models page and use a key from one of them |
模型价格未配置 ("model price not configured") |
The model isn't sold there yet | Use a model listed on the Models page |
429 |
Too many requests, or the upstream is busy | Wait a few seconds and retry |
404 or Invalid URL |
Wrong path — with most providers a doubled or missing /v1; api.foo corrects both, so check for typos |
anthropic SDK: https://api.foo; OpenAI SDK: https://api.foo/v1 |
These messages come from New API, the open-source gateway that api.foo and many Chinese providers run on. More in LLM API errors explained.
Related
- Claude API pricing and cost calculator
- How to get a Claude API key
- Claude Code with a custom API or base URL
- What is api.foo?
Sources
Anthropic documentation, checked November 1, 2026: supported regions, Claude in Microsoft Foundry, prompt caching, pricing. OpenRouter FAQ for its payment methods (checked November 1, 2026).
FAQ
Can I use the Claude API in China?
Not directly from Anthropic. Anthropic's list of supported regions does not include mainland China, Hong Kong or Macau, and its Console requires an account in a supported region. Developers in China usually go through a third-party API service that offers Claude models, or through a company account in a supported region.
Is there a Claude API that accepts Alipay or WeChat Pay?
Anthropic's own API is prepaid by card. Several third-party API services accept Alipay and WeChat Pay; for example, api.foo accepts Alipay, WeChat Pay, cards and USDT and bills in Chinese yuan. OpenRouter also accepts Alipay but bills in US dollars, adds a fee when you buy credits, and users in mainland China often get 403 "This model is not available in your region" for Claude models.
Do I need to change my code to use a third-party Claude API?
Usually only two values. With the official anthropic SDK, set base_url to the provider's address (for api.foo, https://api.foo) and use the provider's key. The request format, model names such as claude-sonnet-5-5 and features like tool use stay the same, as long as the provider forwards the native Messages API.
Is it safe to buy a resold sk-ant- Claude API key?
No. A resold official key belongs to someone else's account, may be shared or stolen, can be revoked at any time, and your prompts pass through an unknown party. A third-party API service is different - it issues its own key and bills you for usage.
Can I use Claude through AWS Bedrock or Google Vertex AI from China?
Those platforms need a cloud account in a region where Claude is offered, and which models you can enable depends on each cloud's model catalog. They suit companies already running on AWS, Google Cloud or Azure outside China, not individual developers looking for a quick setup.
Found a mistake? Email [email protected].