Skip to content

Docs

Tài liệu cho nhà phát triển

AITREE tương thích với OpenAI API. Với hầu hết SDK, bạn chỉ cần đổi base_url và api_key.

Lấy API key

Xác thực

Gửi Bearer token trong header Authorization. Tạo và quản lý key trong bảng điều khiển.

Authorization: Bearer $AITREE_API_KEY

Chat completions

Tham số giống hệt OpenAI /v1/chat/completions, hỗ trợ cả streaming.

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

Các mô hình Claude cũng hỗ trợ giao thức Anthropic gốc: trỏ base_url của SDK chính thức về AITREE (không kèm /v1) và dùng cùng 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)

Tạo ảnh

Giống OpenAI /v1/images/generations; trả về URL ảnh. Tính phí theo lượt gọi hoặc theo token tùy mô hình.

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"
  }'

Tạo video

Video là tác vụ bất đồng bộ: POST /v1/video/generations trả về task_id; gọi GET /v1/video/generations/{id} định kỳ cho đến khi status là succeeded để lấy URL video.

# 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"

Danh sách mô hình

Xem các mô hình hiện khả dụng với key của bạn.

curl https://aitree.ai/v1/models \
  -H "Authorization: Bearer $AITREE_API_KEY"

Key và bảo mật

Mỗi key có thể đặt hạn mức chi tiêu, thời hạn, danh sách mô hình và IP được phép. Nếu key bị lộ, hãy tắt nó trong bảng điều khiển và tạo key mới.

Lỗi

Phản hồi lỗi theo định dạng của OpenAI; error.type cho biết nguồn gốc lỗi.

{
  "error": {
    "message": "insufficient user quota",
    "type": "new_api_error",
    "code": "insufficient_user_quota"
  }
}

Khả năng tương thích

Hoạt động với SDK chính thức của OpenAI, LangChain, LlamaIndex, Cherry Studio, Open WebUI, Cursor và mọi công cụ cho phép tùy chỉnh base_url.

Tài liệu cho nhà phát triển · AITREE