สร้างการตอบกลับแชท
post/v1/chat/completions
สร้างการตอบกลับของโมเดลจากประวัติบทสนทนา รองรับทั้งการตอบกลับแบบสตรีมมิ่งและแบบไม่สตรีมมิ่ง
เข้ากันได้กับ OpenAI Chat Completions API
การยืนยันตัวตน
ส่งคีย์ API ของ OLETOKEN เป็น Bearer token สร้างคีย์ได้ที่หน้า API Keys ในคอนโซล
Authorization: Bearer $OLETOKEN_API_KEYเนื้อหาคำขอ
Content-Type:application/json
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
| model | string | ID ของโมเดล | |
| messages | Message[] | ข้อความในบทสนทนา | |
| role | stringsystemuserassistanttooldeveloper | บทบาทของข้อความ | |
| content | string | MessageContent[] | เนื้อหาของข้อความ | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | URL ของรูปภาพหรือข้อมูล base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | ข้อมูลเสียงที่เข้ารหัส Base64 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | ชื่อผู้ส่ง |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | ID ของการเรียกใช้เครื่องมือ (สำหรับข้อความที่มีบทบาท tool) |
| reasoning_content | string | — | เนื้อหาการให้เหตุผล |
| temperature | number0–2default: 1 | — | อุณหภูมิในการสุ่ม |
| top_p | number0–1default: 1 | — | พารามิเตอร์การสุ่มแบบ nucleus |
| n | integer≥ 1default: 1 | — | จำนวนคำตอบที่ต้องการสร้าง |
| stream | booleandefault: false | — | จะสตรีมการตอบกลับหรือไม่ |
| stream_options | object | — | — |
| include_usage | boolean | — | — |
| stop | string | string[] | — | ลำดับหยุด |
| max_tokens | integer | — | จำนวนโทเค็นสูงสุดที่ต้องการสร้าง |
| max_completion_tokens | integer | — | จำนวนโทเค็นคำตอบสูงสุด |
| presence_penalty | number-2–2default: 0 | — | — |
| frequency_penalty | number-2–2default: 0 | — | — |
| logit_bias | object | — | — |
| user | string | — | — |
| tools | Tool[] | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| description | string | — | — |
| parameters | object | — | นิยามพารามิเตอร์ในรูปแบบ JSON Schema |
| tool_choice | string | objectnoneautorequired | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| response_format | ResponseFormat | — | — |
| type | stringtextjson_objectjson_schema | — | — |
| json_schema | object | — | นิยาม JSON Schema |
| seed | integer | — | — |
| reasoning_effort | stringlowmediumhigh | — | ระดับความพยายามในการให้เหตุผล (สำหรับโมเดลที่รองรับการให้เหตุผล) |
| modalities | string[] | — | — |
| audio | object | — | — |
| voice | string | — | — |
| format | string | — | — |
การตอบกลับ
200สร้างการตอบกลับแล้ว
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
| id | string | — | — |
| object | string | — | — |
| created | integer | — | — |
| model | string | — | — |
| choices | object[] | — | — |
| index | integer | — | — |
| message | Message | — | — |
| role | stringsystemuserassistanttooldeveloper | บทบาทของข้อความ | |
| content | string | MessageContent[] | เนื้อหาของข้อความ | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | URL ของรูปภาพหรือข้อมูล base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | ข้อมูลเสียงที่เข้ารหัส Base64 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | ชื่อผู้ส่ง |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | ID ของการเรียกใช้เครื่องมือ (สำหรับข้อความที่มีบทบาท tool) |
| reasoning_content | string | — | เนื้อหาการให้เหตุผล |
| finish_reason | stringstoplengthtool_callscontent_filter | — | — |
| usage | Usage | — | — |
| prompt_tokens | integer | — | จำนวนโทเค็นของพรอมต์ |
| completion_tokens | integer | — | จำนวนโทเค็นคำตอบ |
| total_tokens | integer | — | จำนวนโทเค็นทั้งหมด |
| prompt_tokens_details | object | — | — |
| cached_tokens | integer | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| image_tokens | integer | — | — |
| completion_tokens_details | object | — | — |
| text_tokens | integer | — | — |
| audio_tokens | integer | — | — |
| reasoning_tokens | integer | — | — |
| system_fingerprint | string | — | — |
400พารามิเตอร์ของคำขอไม่ถูกต้อง
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
| error | object | — | — |
| message | string | — | ข้อความแสดงข้อผิดพลาด |
| type | string | — | ประเภทข้อผิดพลาด |
| param | string | null | — | พารามิเตอร์ที่เกี่ยวข้อง |
| code | string | null | — | รหัสข้อผิดพลาด |
429เกินขีดจำกัดอัตราการเรียกใช้งาน
| ฟิลด์ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
| error | object | — | — |
| message | string | — | ข้อความแสดงข้อผิดพลาด |
| type | string | — | ประเภทข้อผิดพลาด |
| param | string | null | — | พารามิเตอร์ที่เกี่ยวข้อง |
| code | string | null | — | รหัสข้อผิดพลาด |
ตัวอย่างคำขอ
curl -X POST 'https://api.oletoken.ai/v1/chat/completions' \
-H "Authorization: Bearer $OLETOKEN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4",
"messages": []
}'
