Using Claude API from China: OpenAI SDK, Claude Code and Cursor setup with troubleshooting
Direct answer: A gateway using official channels provides stable Claude API access. Register for a key, point base_url to its OpenAI-compatible endpoint, or configure Anthropic-compatible variables for Claude Code or Cursor. Below are three configurations and common error checks.
Introduction
Last Tuesday, independent developer Kai posted: "Claude API registration is stuck at payment. My Visa failed three times and the project has waited two days." Others shared the experience. The obstacle was direct registration and payment requirements for developers in China.
An alternative is an officially sourced gateway with transparent billing and access to official Claude models. You still use models such as Claude Opus and Sonnet; the intermediary handles registration, payments, routing and reliability. This tutorial covers getting a key, three setup options and troubleshooting.
Key takeaways
- Get a key: register → create a console key → copy base_url (
https://api.yomiapi.com/v1).- Option 1: OpenAI SDK compatibility. Change base_url and use a model such as
claude-sonnet-5,claude-opus-4-8, subject to Yomi's current model list.- Option 2: configure Claude Code with
ANTHROPIC_BASE_URL+ANTHROPIC_AUTH_TOKENenvironment variables.- Option 3: set a custom base_url in Cursor's Settings → Models.
- Common errors: 401 authentication failures, 429 rate limits and 504 timeouts.
- RMB top-ups through WeChat Pay / Alipay, token metering and itemized records are supported.
Get your key: register → create a key → copy base_url
Step 1: Register. Visit the Yomi API and register with email; no overseas payment method is required.
Step 2: Create an API key. Open the console's Keys page and generate a key. Use one per project to isolate permissions and quotas; replace an exposed key without affecting other projects.
Step 3: Save base_url. The OpenAI-compatible address is:
https://api.yomiapi.com/v1
Remember these three values:api_key, base_url, model(the model name). All three options use them.
Option 1: OpenAI SDK compatibility (recommended)
If you already use the official OpenAI SDK, connect Claude by changing base_url. Python example:
from openai import OpenAI
client = OpenAI(
api_key="sk-YOUR-YOMI-API-KEY", # Key created in the console
base_url="https://api.yomiapi.com/v1" # Yomi OpenAI-compatible endpoint
)
resp = client.chat.completions.create(
model="claude-sonnet-5", # Use model names from the Yomi models page
messages=[{"role": "user", "content": "Hello, introduce yourself in one sentence"}]
)
print(resp.choices[0].message.content)
The same applies to Node.js:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-YOUR-YOMI-API-KEY",
baseURL: "https://api.yomiapi.com/v1",
});
const resp = await client.chat.completions.create({
model: "claude-sonnet-5",
messages: [{ role: "user", content: "Hello" }],
});
console.log(resp.choices[0].message.content);
Key points:
- The response format matches OpenAI, preserving existing code structure.
- Common model names:
claude-sonnet-5for everyday work and coding, andclaude-opus-4-8for complex reasoning and long documents —check the Claude model list for current availability. Switch models by changing model.
Option 2: Claude Code (ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN)
Claude Code is Anthropic's official terminal coding tool. Configure environment variables to use a gateway. First install the CLI:
npm install -g @anthropic-ai/claude-code
Then set environment variables in ~/.zshrc or ~/.bashrc on macOS/Linux, or in Windows system settings:
# Gateway Anthropic-compatible endpoint (without /v1; Claude Code appends /v1/messages)
export ANTHROPIC_BASE_URL="https://api.yomiapi.com"
# Use your Yomi key as the authentication token
export ANTHROPIC_AUTH_TOKEN="sk-YOUR-YOMI-API-KEY"
# Default main model; optionally change to claude-opus-4-8
export ANTHROPIC_MODEL="claude-sonnet-5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-8"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5"
export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-5"
# Clear the official key to avoid configuration conflicts
export ANTHROPIC_API_KEY=""
Warning:
ANTHROPIC_BASE_URLis required. Without it, Claude Code sends requests to Anthropic's servers instead of Yomi API.
After configuration, run source ~/.zshrc, then enter claude to start and run /status to verify the base URL points to the gateway. Once correct, start coding with Claude Code.
Endpoint requirements vary between tool versions.Use the commands in the Yomi console documentation section on connecting Claude Code, where setup commands can be copied directly.
Option 3: Cursor with a custom base_url
Cursor supports custom model endpoints. Follow these steps:
- Open Cursor → Settings → Models.
- Under OpenAI API Key , enter your Yomi key.
- Under Override OpenAI Base URL , enter
https://api.yomiapi.com/v1. - Add a model name, such as
claude-sonnet-5,claude-opus-4-8, then save to select Claude in chat and editing.
Cursor can then use Claude for completion, chat and review, billed by token against your Yomi balance.
Troubleshooting: 401 / 429 / 504
Match the error to these checks:
| Error | Meaning | Checks |
|---|---|---|
| 401 Unauthorized | Authentication failed | Check that api_key is complete without extra spaces, the key is enabled, and base_url has no extra / or incorrect path |
| 429 Too Many Requests | Rate limit reached | Check concurrency, separate project keys and review console usage; if needed, upgrade a monthly subscription for a stable quota |
| 504 Gateway Timeout | Upstream timeout | Often due to large requests or route fluctuations. Split requests, enable stream=true and retry later; the gateway can switch to backups |
One recommendation: keep keys isolated by project so an affected key can be replaced without disrupting other services. This is a general best practice.
RMB top-ups: WeChat Pay / Alipay and token billing
Gateways address a difficult part of direct access:RMB top-ups through WeChat Pay and Alipay, with precise token metering, separate input/output rates and itemized records. Start with a few dozen yuan, confirm latency and stability, then scale. Our approach was to top up 50 yuan and run real requests for a week before deciding.
Final thoughts
Returning to that stalled Visa payment —let a compliant gateway handle registration, payment, routing and reliability while you focus on your product.
Choose the option that fits:OpenAI SDK for quick integration into existing projects; Claude Code for terminal coding; Cursor for everyday IDE use. Your first successful setup may take only a few minutes.
Spend a small amount testing all three options and use Yomi's model list to compare latency and availability before choosing a primary model.Switching models changes one field and costs little.
Start now: register, copy the code and make your first Claude call within ten minutes.
Yomi API