使用 OpenAI 聊天補全 API 進行對話。這是經典的 OpenAI 聊天 API 格式。
/api/ai/v1/chat/completionsBearer YOUR_API_KEY| 參數 | 類型 | 必要 | 說明 |
|---|---|---|---|
model | string | 必要 | 模型名稱,例如 deepseek-v4.1-flash、qwen3.8-max |
messages | array | 必要 | 訊息陣列,格式為 |
max_tokens | integer | 選填 | 最大輸出 Token 數 |
temperature | float | 選填 | 取樣溫度,控制隨機性(0-2) |
stream | boolean | 選填 | 啟用串流回應,設為 true 以使用 SSE |
| 參數 | 類型 | 說明 |
|---|---|---|
id | string | 唯一回應識別碼 |
model | string | 實際使用的模型 |
choices | array | 回應選項陣列,通常取第一個 |
usage | object | Token 使用統計 |
curl --location 'https://your-domain.com/api/ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"model": "deepseek-v4.1-flash",
"messages": [
{"role": "user", "content": "Hello, who are you?"}
],
"max_tokens": 1000,
"temperature": 0.7
}'import requests
response = requests.post(
"https://your-domain.com/api/ai/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
json={
"model": "deepseek-v4.1-flash",
"messages": [
{"role": "user", "content": "Hello, who are you?"}
],
"max_tokens": 1000,
"temperature": 0.7
}
)
print(response.json())curl --location 'https://your-domain.com/api/ai/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"model": "deepseek-v4.1-flash",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 1000,
"stream": true
}'