Docs
接入文档
本站兼容 OpenAI、Claude、Gemini 三种原生格式。原来能用官方接口的代码和工具,一般只要改两样:接口地址和密钥。
1. 拿到密钥
- 注册账号,登录后进入控制台。
- 在「密钥」页面点「创建」,可以给密钥设额度上限、过期时间和能用的模型。
- 复制生成的
sk- 开头的密钥。密钥等于你的钱,不要发到群里或提交到代码仓库。
2. 接口地址
| 用途 | 地址 |
| OpenAI SDK / 大多数工具 | {BASE}/v1 |
| Claude SDK / Claude Code | {BASE} |
| Gemini | {BASE}/v1beta |
3. OpenAI 格式
curl {BASE}/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-d '{"model": "{MODEL}", "stream": true,
"messages": [{"role": "user", "content": "你好"}]}'
Python
from openai import OpenAI
client = OpenAI(base_url="{BASE}/v1", api_key="sk-你的密钥")
resp = client.chat.completions.create(
model="{MODEL}",
messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)
4. Claude 格式与 Claude Code
curl {BASE}/v1/messages \
-H "x-api-key: sk-你的密钥" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-模型名", "max_tokens": 1024,
"messages": [{"role": "user", "content": "你好"}]}'
Claude Code
在终端里设置这两个环境变量,再运行 claude:
export ANTHROPIC_BASE_URL={BASE}
export ANTHROPIC_AUTH_TOKEN=sk-你的密钥
claude
5. Gemini 格式
curl "{BASE}/v1beta/models/gemini-模型名:generateContent" \
-H "x-goog-api-key: sk-你的密钥" \
-H "content-type: application/json" \
-d '{"contents": [{"parts": [{"text": "你好"}]}]}'
| 工具 | 怎么填 |
| Cherry Studio | 设置 → 模型服务 → 添加「OpenAI 兼容」,地址填 {BASE},再填密钥;也可以在控制台「密钥」页一键导入 |
| Cursor | Settings → Models → 打开「Override OpenAI Base URL」,填 {BASE}/v1,API Key 填密钥 |
| Codex CLI | 见下方配置 |
# ~/.codex/config.toml
model = "{MODEL}"
model_provider = "relay"
[model_providers.relay]
name = "relay"
base_url = "{BASE}/v1"
env_key = "RELAY_API_KEY"
wire_api = "responses"
# 然后:export RELAY_API_KEY=sk-你的密钥
7. 充值与计费
- 充值方式:购买兑换码。付款后马上拿到兑换码,在控制台「钱包」粘贴兑换即可到账。兑换码 90 天内有效,只能用一次。
- 按实际用量扣费:输入 tokens、输出 tokens 分开计价,命中缓存的部分更便宜。价格见模型广场。
- 每次调用的模型、tokens、费用都能在控制台「使用记录」里查到。
- 请求失败(上游出错、超时)不扣费。
8. 常见错误
| 报错 | 原因 | 怎么办 |
401 | 密钥不对、已删除或已过期 | 到控制台检查密钥,重新复制 |
403 | 这个密钥没有开通该模型 | 在密钥设置里勾上这个模型,或换一个密钥 |
404 model not found | 模型名写错,或该模型已下架 | 到模型广场复制准确的模型名 |
| 额度不足 | 账户余额或密钥额度用完了 | 到控制台「钱包」兑换充值,或调高密钥额度 |
429 | 请求太快,触发限流 | 降低并发,稍等再试 |
524 | 非流式请求超过约 120 秒没返回 | 加上 "stream": true 用流式输出 |
5xx | 上游临时故障 | 系统会自动换线路重试;持续出现请联系客服 |
Docs
Documentation
This gateway speaks the native OpenAI, Claude and Gemini formats. Code and tools that work with the official APIs usually need two changes: the base URL and the API key.
1. Get a key
- Sign up and open the console.
- On the Keys page, click Create. You can set a spending limit, an expiry date and allowed models.
- Copy the key starting with
sk-. Treat it like cash — never paste it in chats or commit it.
2. Base URL
| Use | Address |
| OpenAI SDK / most tools | {BASE}/v1 |
| Claude SDK / Claude Code | {BASE} |
| Gemini | {BASE}/v1beta |
3. OpenAI format
curl {BASE}/v1/chat/completions \
-H "Authorization: Bearer sk-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "{MODEL}", "stream": true,
"messages": [{"role": "user", "content": "Hello"}]}'
Python
from openai import OpenAI
client = OpenAI(base_url="{BASE}/v1", api_key="sk-YOUR_KEY")
resp = client.chat.completions.create(
model="{MODEL}",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
4. Claude format and Claude Code
curl {BASE}/v1/messages \
-H "x-api-key: sk-YOUR_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-MODEL", "max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello"}]}'
Claude Code
export ANTHROPIC_BASE_URL={BASE}
export ANTHROPIC_AUTH_TOKEN=sk-YOUR_KEY
claude
5. Gemini format
curl "{BASE}/v1beta/models/gemini-MODEL:generateContent" \
-H "x-goog-api-key: sk-YOUR_KEY" \
-H "content-type: application/json" \
-d '{"contents": [{"parts": [{"text": "Hello"}]}]}'
| Tool | Setup |
| Cherry Studio | Settings → Model Providers → add "OpenAI compatible", base {BASE}, then your key. Or use one-click import on the Keys page. |
| Cursor | Settings → Models → enable "Override OpenAI Base URL": {BASE}/v1, and paste your key |
| Codex CLI | See below |
# ~/.codex/config.toml
model = "{MODEL}"
model_provider = "relay"
[model_providers.relay]
name = "relay"
base_url = "{BASE}/v1"
env_key = "RELAY_API_KEY"
wire_api = "responses"
# then: export RELAY_API_KEY=sk-YOUR_KEY
7. Top-up and billing
- How to top up: buy a redemption code. You get it as soon as you pay — paste it under Wallet in your console and it is credited instantly. Codes are valid for 90 days and work once.
- Pay per use: input and output tokens are priced separately; cached input costs less. See Models.
- Every call's model, tokens and cost are listed under Usage in your console.
- Failed requests (upstream errors, timeouts) are not charged.
8. Common errors
| Error | Cause | Fix |
401 | Key is wrong, deleted or expired | Check the key in your console and copy it again |
403 | Model not enabled for this key | Allow the model in key settings, or use another key |
404 model not found | Model name is wrong or unpublished | Copy the exact name from Models |
| Insufficient quota | Balance or key limit used up | Redeem a code under Wallet, or raise the key limit |
429 | Too many requests | Lower concurrency and retry later |
524 | Non-streaming request took over ~120 s | Add "stream": true |
5xx | Temporary upstream failure | Requests are retried on another route automatically; contact support if it persists |