開發者
文檔
ad9.io 相容 Anthropic 與 OpenAI 兩種協議。已在用 Claude Code、Codex、官方 SDK 或 curl?通常只要把 base_url 換成 api.ad9.io、帶上你的 ad9 Key 就能跑。
快速開始
一鍵配置(Claude Code)
在終端執行下面一行,貼上你的 ad9 Key 即可把 Claude Code 指向 ad9.io:
curl -fsSL https://ad9.io/install/claude-code.sh | bash
用 Codex 或其他 OpenAI 相容工具?改用:
curl -fsSL https://ad9.io/install/codex.sh | bash
Windows(PowerShell):
irm https://ad9.io/install/claude-code.ps1 | iex
直接用 curl
curl https://api.ad9.io/api/v1/messages \ -H "x-api-key: ad9-你的key" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{"model":"claude-haiku-4-5","max_tokens":256,"messages":[{"role":"user","content":"Hello!"}]}'
Python (anthropic SDK)
pip install anthropic import anthropic client = anthropic.Anthropic(base_url="https://api.ad9.io/api", api_key="ad9-YOUR_KEY") msg = client.messages.create(model="claude-haiku-4-5", max_tokens=256, messages=[{"role":"user","content":"Hello!"}]) print(msg.content[0].text)
Node.js (@anthropic-ai/sdk)
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ baseURL: "https://api.ad9.io/api", apiKey: "ad9-YOUR_KEY" }); const msg = await client.messages.create({ model: "claude-haiku-4-5", max_tokens: 256, messages: [{ role: "user", content: "Hello!" }] }); console.log(msg.content[0].text);
認證與端點
用帳戶頁生成的 ad9 Key 認證。Anthropic 協議用 x-api-key 標頭,OpenAI 協議用 Authorization: Bearer。按你的 SDK 選對應 base_url:
| 協議 / 工具 | base_url | 認證標頭 |
|---|---|---|
| Anthropic(Claude Code, SDK) | https://api.ad9.io/api | x-api-key: ad9-… |
| OpenAI(Codex, SDK) | https://api.ad9.io/openai/v1 | Authorization: Bearer ad9-… |
| Gemini | https://api.ad9.io/gemini | x-goog-api-key: ad9-… |
查詢額度與用量:GET /api/v1/key(回傳檔位、日額、已用、剩餘)。到 帳戶頁 可複製 Key、看用量、重置。
模型
免費檔開放中低階模型;opus / 旗艦 gpt / fable 等高階模型需付費檔(訂閱、加油包或錢包)。完整用 GET /api/v1/models 查。
| 可用檔位 | 模型(示例) |
|---|---|
| 免費 + 付費 | claude-sonnet-5 · claude-haiku-4-5 · gemini-2.5-flash · gpt-5.6-mini · gpt-5.6-nano |
| 僅付費 | claude-opus-4-8 · claude-fable-5 · gpt-5.6 · 更多旗艦 |
錯誤碼
錯誤體是標準協議格式。撞到「可升級」的牆(付費模型 / 配額 / 並發)時,錯誤體會多帶一個機器可讀的 ad9_upgrade 欄位,方便你的程式引導升級。
| 狀態 | 含義 | 怎麼辦 |
|---|---|---|
401 | Key 無效或未激活 | 檢查 Key 是否正確、是否已重置 |
403 | 免費檔調了付費模型 | 換中低階模型,或升級付費檔 |
402 | 配額用盡 / 無可用額度 | 等 00:00(UTC+8,新加坡時間)刷新,或充值 / 升級 / 邀請好友 |
429 | 並發超限 | 依 Retry-After 重試;付費檔並發更高 |
ad9_upgrade 示例(402):
{
"error": { "type": "billing_error", "message": "Daily quota exhausted…" },
"ad9_upgrade": {
"reason": "quota_exhausted",
"resets_at": "00:00 UTC+8 (Asia/Singapore)",
"upgrade_url": "https://ad9.io/pricing"
}
}
免費檔限制
- $70 免費額度(14 天 · 每日 $5),00:00(UTC+8,新加坡時間)自動刷新。
- 2 個並發請求(付費檔 10 個)。
- 中低階模型(sonnet / haiku / mini 等);高階需付費。
- 14 天有效期:免費 Key 到期後日額清零,可付費、充值或重新領取。
- 全站受全局免費池保護,池滿時免費發放暫停;付費檔不受影響。
準備好了?免費獲取 API Key,或看 定價。