Claude API · China

Calling the Claude API from China (Top-Up, Proxy/Relay, and Code Examples)

This page is for developers who call Claude from their code (not Claude Code users). AICodeWith provides both the Anthropic-native API and an OpenAI-compatible API. It is directly accessible from China and lets you top up using payment methods available in China, with per-token billing.

Last checked

Why you can't buy a Claude API key from China

Anthropic's API console requires registration from a supported region and a foreign credit card for payment; network access from China is also unstable. As a result, many developers in China run into three problems: they can't register, can't pay, and can't connect.

Comparing options (Anthropic's own API, cloud providers, relay/proxy)

Anthropic's own APIOverseas cloud providers (e.g., AWS Bedrock, Google Vertex AI)Relay / proxy (AICodeWith)
PaymentOverseas credit cardOverseas cloud accountChina payment, prepaid balance
Network access from ChinaUnstableDepends on regionDirectly accessible
IntegrationAnthropic SDKCloud provider SDKAnthropic SDK or OpenAI-compatible
Activation requirementsRegion restrictionsEnterprise verification, quota requestRegister and create a Key

Top-Up and Billing

  • Each request is charged based on the actual input and output tokens consumed; usage records are visible in the console.
  • Supports top-ups via payment methods available in China; you can also buy prepaid plans. Balance is valid for 12 months and does not reset monthly.
  • Balance that remains unused for 90 days is refundable, with a 10% processing fee. See the refund policy for details.

Top-Up and PlansGet API Key

Code Examples (Anthropic SDK, OpenAI-Compatible)

Python · Anthropic SDK
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.aicodewith.ai",
    api_key="你的_API_KEY",
)

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "你好"}],
)
print(msg.content[0].text)
Python · OpenAI-compatible (streaming)
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aicodewith.ai/v1",
    api_key="你的_API_KEY",
)

resp = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "你好"}],
    stream=True,
)
for chunk in resp:
    print(chunk.choices[0].delta.content or "", end="")
curl
curl https://api.aicodewith.ai/v1/chat/completions \
  -H "Authorization: Bearer 你的_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "你好"}]}'

The model names in the examples are for demonstration only. Use the model IDs listed on the models page.

Models and Pricing

The model IDs, context lengths, and real-time prices for all Claude models are on the models page. Prices vary by route; refer to the real-time data on the models page.

Claude Model OverviewModels and Real-Time Prices

FAQ

How do I buy a Claude API Key?

Register with AICodeWith, top up, then create a Key on the API Keys page in the console; you can call Claude from your code immediately.

Can I pay with a credit card issued in China?

You can top up with payment methods available in China; no overseas credit card is required.

Is there a difference between proxy and relay?

In common usage in China, they refer to the same thing: an API endpoint compatible with the Claude API that forwards requests to the model for you. You only need to change the base_url and Key.

Does it support streaming output?

Yes. Both the Anthropic SDK and the OpenAI-compatible API support streaming output (stream).

Ready to try it?

Billing is per token from a prepaid balance. Rate and concurrency limits apply, and you can set daily, monthly or total spend caps on each API key.

Related

AICodeWith is an independent third-party API service and has no affiliation with Anthropic or OpenAI. Claude, Claude Code, Codex, and other names belong to their respective owners. Prices are subject to the real-time data on the models page; rate and concurrency limits apply; refunds incur a 10% processing fee. See the refund policy for details.