身分驗證
在 Authorization 標頭中帶入 Bearer Token。金鑰可在主控台建立與管理。
Authorization: Bearer $AITREE_API_KEY對話補全
參數與 OpenAI /v1/chat/completions 相同,支援串流輸出。
curl https://aitree.ai/v1/chat/completions \
-H "Authorization: Bearer $AITREE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash-0731",
"stream": true,
"messages": [{ "role": "user", "content": "用一句话解释什么是算力中转站" }]
}'Anthropic Messages
Claude 模型也支援 Anthropic 原生協定:將官方 SDK 的 base_url 指向 AITREE(不含 /v1),並使用同一把 API 金鑰。
import anthropic
client = anthropic.Anthropic(base_url="https://aitree.ai", api_key="YOUR_AITREE_KEY")
msg = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)圖片生成
與 OpenAI /v1/images/generations 相同,回傳圖片網址。依模型按次或按 token 計費。
curl https://aitree.ai/v1/images/generations \
-H "Authorization: Bearer $AITREE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-5-0-260128",
"prompt": "a glowing compute tree at night, cinematic",
"size": "1024x1024"
}'影片生成
影片為非同步任務:POST /v1/video/generations 會回傳 task_id;以 GET /v1/video/generations/{id} 輪詢,直到 status 為 succeeded 即可取得影片網址。
# 1. submit
curl https://aitree.ai/v1/video/generations \
-H "Authorization: Bearer $AITREE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "model": "doubao-seedance-2-0-fast-260128", "prompt": "drone shot through a forest of light", "seconds": "5" }'
# 2. poll until status is "succeeded"
curl https://aitree.ai/v1/video/generations/$TASK_ID \
-H "Authorization: Bearer $AITREE_API_KEY"模型清單
查詢這把金鑰目前可用的模型。
curl https://aitree.ai/v1/models \
-H "Authorization: Bearer $AITREE_API_KEY"金鑰與安全
每把金鑰都可設定消費上限、有效期限、模型白名單與 IP 白名單。金鑰外洩時,請在主控台停用並建立新的金鑰。
錯誤
錯誤回應沿用 OpenAI 格式,error.type 會標示錯誤來源。
{
"error": {
"message": "insufficient user quota",
"type": "new_api_error",
"code": "insufficient_user_quota"
}
}相容性
可直接搭配 OpenAI 官方 SDK、LangChain、LlamaIndex、Cherry Studio、Open WebUI、Cursor,以及任何支援自訂 base_url 的工具。