ใช้ OpenAI Chat Completions API สำหรับการสนทนา นี่คือรูปแบบ API การสนทนาของ OpenAI แบบคลาสสิก
/api/ai/v1/chat/completionsBearer YOUR_API_KEY| พารามิเตอร์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
model | string | จำเป็น | ชื่อโมเดล เช่น deepseek-v4.1-flash, qwen3.8-max |
messages | array | จำเป็น | อาร์เรย์ข้อความในรูปแบบ |
max_tokens | integer | ไม่บังคับ | จำนวนโทเค็นเอาต์พุตสูงสุด |
temperature | float | ไม่บังคับ | อุณหภูมิการสุ่ม ควบคุมความสุ่ม (0-2) |
stream | boolean | ไม่บังคับ | เปิดการตอบสนองแบบสตรีม ตั้งค่าเป็น true สำหรับ SSE |
| พารามิเตอร์ | ประเภท | คำอธิบาย |
|---|---|---|
id | string | ตัวระบุการตอบสนองที่ไม่ซ้ำกัน |
model | string | โมเดลที่ใช้จริง |
choices | array | อาร์เรย์ของตัวเลือกการตอบสนอง โดยทั่วไปเลือกตัวเลือกแรก |
usage | object | สถิติการใช้โทเค็น |
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
}'