介面指南
使用 API 金鑰
2. 建立並儲存 API 金鑰
在控制台建立 API 金鑰,可設定每月支出上限。新金鑰可再次檢視。舊金鑰若沒有加密副本,可補存原始金鑰或輪替。輪替後的 24 小時內,新舊金鑰共用每月額度。每個應用程式請使用獨立金鑰,並避免將金鑰放入瀏覽器程式碼或公開儲存庫。
3. 選擇模型與協議
使用實時模型目錄中的公開別名。OpenAI 相容客戶端使用 /v1;Anthropic 相容客戶端使用 /anthropic。不要把供應商內部模型 ID 當作平臺別名。
4. 發起請求
SDK 接收 Base URL 並自動拼接介面路徑;curl 需要完整介面 URL。將金鑰放在服務端環境變數中,按所用協議傳送認證頭;流式響應使用 stream: true。
認證與錯誤處理
401:檢查金鑰與認證頭;402:檢查錢包餘額;403:檢查金鑰狀態與月度額度;429:降低頻率並退避重試;503:稍後重試或檢視可用模型。
示例程式碼中的欄位名、模型別名和介面路徑保持原樣,可直接用於開發。
完整技術參考(英文)
Getting started
Use your API key
Token Relay exposes two upstream-compatible endpoints. Once you have a key, you can keep using your existing OpenAI or Anthropic client libraries — only the base_url and the API key change.
1. Get a key
- Sign in to the developer console.
- Open API keys.
- Click Create API key. Give it a name (something like
local-devorprod-app) and optionally a monthly spend cap in CN¥. - A token starting with
tsk_appears in the reveal banner. Save it securely. Newly encrypted keys can be viewed again in the console.
2. Endpoints
The relay exposes two protocols. Pick the one your client already speaks.
| Protocol | Base URL | Auth header |
|---|---|---|
| OpenAI Chat Completions | https://chinzy.com/v1 | Authorization: Bearer tsk_... |
| Anthropic Messages (streaming) | https://chinzy.com/anthropic/v1 | x-api-key: tsk_... |
3. Pick a model
Pass any of our public model aliases as the model field. The full list is at Models. A few common ones:
gpt-5.2,gpt-5,gpt-5-mini,gpt-5.4-mini— OpenAI familyclaude-sonnet-4.5,claude-haiku-4.5,claude-opus-4.5— Anthropic familydeepseek-v3.2,kimi-k2-thinking,glm-4.6— open-weight families
You always pass the platform alias, never the upstream-specific id. Behind the scenes the relay picks a healthy upstream and routes the call there with automatic failover.
4. Examples
curl
curl https://chinzy.com/v1/chat/completions \
-H "Authorization: Bearer $TOKEN_RELAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.2",
"messages": [
{"role": "user", "content": "Hi in one sentence"}
]
}'Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKEN_RELAY_KEY"],
base_url="https://chinzy.com/v1",
)
resp = client.chat.completions.create(
model="gpt-5.2",
messages=[{"role": "user", "content": "Hi in one sentence"}],
)
print(resp.choices[0].message.content)Node.js (OpenAI SDK)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.TOKEN_RELAY_KEY,
baseURL: 'https://chinzy.com/v1',
});
const resp = await client.chat.completions.create({
model: 'gpt-5.2',
messages: [{ role: 'user', content: 'Hi in one sentence' }],
});
console.log(resp.choices[0].message.content);Anthropic SDK (streaming)
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.TOKEN_RELAY_KEY,
baseURL: 'https://chinzy.com/anthropic',
});
const stream = await client.messages.stream({
model: 'claude-sonnet-4.5',
max_tokens: 512,
messages: [{ role: 'user', content: 'Hi in one sentence' }],
});
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text);
}
}5. Common errors
| Status | Meaning | Fix |
|---|---|---|
401 | Token missing, malformed, or disabled. | Verify the Authorization header value matches the token from the reveal banner. Check API keys — disabled keys show a red badge. |
402 / 403 "balance too low" | Wallet has no balance to settle this request. | Top up at Billing. |
403 "monthly spend cap reached" | This specific key's monthly quota is exhausted. | Either wait for the next calendar month, raise the cap on API keys, or use a different key. |
429 | You crossed the per-IP rate limit (300 req/min for relay). | Backoff and retry; widen the gap between requests. |
503 | Every upstream that serves this alias is down. Rare — the relay already auto-retries on intermittent failures. | Try a sibling alias (e.g. gpt-5-mini instead of gpt-5.2). If persistent, check your status page. |
6. Tips
- One key per app. Cheap to rotate; lets you disable a leaked credential without breaking other clients.
- Set a monthly cap. A runaway dev loop is much easier to recover from when each key is bounded.
- Watch usage at /console/usage. The page shows per-model + per-key spend, recent calls with status codes, and a CSV export for accounting.
- Streaming is supported on both protocols. Just pass
stream: truein the OpenAI SDK or usemessages.stream()with Anthropic.
Found something missing or wrong in this doc? Open an issue or ping an admin.