Docs
เอกสารสำหรับนักพัฒนา
AITREE ใช้ OpenAI API เป็นมาตรฐาน SDK ส่วนใหญ่เพียงเปลี่ยน base_url และ api_key ก็ใช้งานได้
การยืนยันตัวตน
ส่ง Bearer token ในส่วนหัว Authorization สร้างและจัดการคีย์ได้ในคอนโซล
Authorization: Bearer $AITREE_API_KEYChat Completions
ใช้พารามิเตอร์เดียวกับ 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 แบบเนทีฟด้วย: ชี้ base_url ของ SDK อย่างเป็นทางการไปที่ AITREE (ไม่ต้องมี /v1) และใช้ API key เดียวกัน
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 คืนค่าเป็น URL ของภาพ คิดเงินต่อครั้งหรือต่อโทเค็นตามโมเดล
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 เพื่อรับ URL วิดีโอ
# 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 เองได้