Tài liệuTham chiếu APIOpenAI · Chat

OpenAI · Chat Completions

POST /v1/chat/completions

Xác thực: trang xác thực. Base: danh sách giao thức. Lệnh dò: kiểm tra curl.

http
Authorization: Bearer sk-xxxx
Content-Type: application/json
bash
curl https://api.daoxe.com/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxx" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "sao chép từ /v1/models",
    "messages": [{"role":"user","content":"ping"}],
    "max_tokens": 64
  }'

Phản hồi thành công (cấu trúc)

json
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 20,
    "total_tokens": 30
  }
}

Mảnh luồng (ví dụ)

text
data: {"choices":[{"delta":{"content":"Hi"}}]}
data: [DONE]

Ví dụ lỗi

json
{"error":{"message":"Invalid token","code":401}}
{"error":{"message":"Insufficient quota"}}
{"error":{"message":"Rate limit exceeded"}}

Thêm lỗi: mã lỗi. Mô hình: bảng mô hình.