Tạo chat completion
post/v1/chat/completions
Tạo phản hồi của mô hình từ lịch sử hội thoại. Hỗ trợ cả phản hồi truyền trực tuyến và không truyền trực tuyến.
Tương thích với OpenAI Chat Completions API.
Xác thực
Gửi khóa API OLETOKEN dưới dạng token Bearer. Khóa được tạo tại trang API Keys trong bảng điều khiển.
Authorization: Bearer $OLETOKEN_API_KEYNội dung yêu cầu
Content-Type:application/json
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| model | string | ID mô hình | |
| messages | Message[] | Các tin nhắn hội thoại | |
| role | stringsystemuserassistanttooldeveloper | Vai trò của tin nhắn | |
| content | string | MessageContent[] | Nội dung tin nhắn | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | URL hình ảnh hoặc dữ liệu base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Dữ liệu âm thanh mã hóa Base64 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | Tên người gửi |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | ID gọi công cụ (cho tin nhắn có vai trò tool) |
| reasoning_content | string | — | Nội dung suy luận |
| temperature | number0–2default: 1 | — | Nhiệt độ lấy mẫu |
| top_p | number0–1default: 1 | — | Tham số lấy mẫu nucleus |
| n | integer≥ 1default: 1 | — | Số lượng completion cần tạo |
| stream | booleandefault: false | — | Có truyền trực tuyến phản hồi hay không |
| stream_options | object | — | — |
| include_usage | boolean | — | — |
| stop | string | string[] | — | Các chuỗi dừng |
| max_tokens | integer | — | Số token tối đa cần tạo |
| max_completion_tokens | integer | — | Số token completion tối đa |
| 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 | — | Định nghĩa tham số theo định dạng JSON Schema |
| tool_choice | string | objectnoneautorequired | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| response_format | ResponseFormat | — | — |
| type | stringtextjson_objectjson_schema | — | — |
| json_schema | object | — | Định nghĩa JSON Schema |
| seed | integer | — | — |
| reasoning_effort | stringlowmediumhigh | — | Mức độ suy luận (cho các mô hình hỗ trợ suy luận) |
| modalities | string[] | — | — |
| audio | object | — | — |
| voice | string | — | — |
| format | string | — | — |
Phản hồi
200Đã tạo phản hồi
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | — | — |
| object | string | — | — |
| created | integer | — | — |
| model | string | — | — |
| choices | object[] | — | — |
| index | integer | — | — |
| message | Message | — | — |
| role | stringsystemuserassistanttooldeveloper | Vai trò của tin nhắn | |
| content | string | MessageContent[] | Nội dung tin nhắn | |
| type | stringtextimage_urlinput_audiofilevideo_url | — | — |
| text | string | — | — |
| image_url | object | — | — |
| url | string | — | URL hình ảnh hoặc dữ liệu base64 |
| detail | stringlowhighauto | — | — |
| input_audio | object | — | — |
| data | string | — | Dữ liệu âm thanh mã hóa Base64 |
| format | stringwavmp3 | — | — |
| file | object | — | — |
| filename | string | — | — |
| file_data | string | — | — |
| file_id | string | — | — |
| video_url | object | — | — |
| url | string | — | — |
| name | string | — | Tên người gửi |
| tool_calls | ToolCall[] | — | — |
| id | string | — | — |
| type | string | — | — |
| function | object | — | — |
| name | string | — | — |
| arguments | string | — | — |
| tool_call_id | string | — | ID gọi công cụ (cho tin nhắn có vai trò tool) |
| reasoning_content | string | — | Nội dung suy luận |
| finish_reason | stringstoplengthtool_callscontent_filter | — | — |
| usage | Usage | — | — |
| prompt_tokens | integer | — | Số token prompt |
| completion_tokens | integer | — | Số token completion |
| total_tokens | integer | — | Tổng số token |
| 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 | — | — |
400Tham số yêu cầu không hợp lệ
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| error | object | — | — |
| message | string | — | Thông báo lỗi |
| type | string | — | Loại lỗi |
| param | string | null | — | Tham số liên quan |
| code | string | null | — | Mã lỗi |
429Vượt quá giới hạn tần suất
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| error | object | — | — |
| message | string | — | Thông báo lỗi |
| type | string | — | Loại lỗi |
| param | string | null | — | Tham số liên quan |
| code | string | null | — | Mã lỗi |
Ví dụ yêu cầu
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": []
}'
