Chat Completions
Endpoint hội thoại cốt lõi, tương thích với định dạng OpenAI Chat Completions. Hỗ trợ đầu vào đa phương thức, phát trực tuyến, gọi tool và các mô hình reasoning.
Yêu cầu
curl https://console.dotouch.ltd/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "deepseek-v4-1-flash-261017",
"messages": [
{ "role": "system", "content": "You are a concise assistant" },
{ "role": "user", "content": "Hello" }
],
"stream": false
}'
RequestREQUEST
POST
https://console.dotouch.ltd/v1/chat/completionsResponseRESPONSE
Fill in the request and hit Send — the response shows up here
Thân yêu cầu
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
model | string | Có | Tên mô hình, xem Liệt kê mô hình |
messages | array | Có | Các tin nhắn hội thoại, xem cấu trúc tin nhắn ở dưới |
stream | boolean | Không | Xuất dữ liệu dạng stream (SSE), mặc định false |
temperature | number | Kh ông | Nhiệt độ lấy mẫu 0–2, mặc định 1 — càng thấp càng ổn định |
top_p | number | Không | Lấy mẫu nucleus; chỉ điều chỉnh tham số này hoặc temperature, không điều chỉnh cả hai |
max_tokens | number | Không | Số token tối đa được sinh ra (các mô hình mới dùng max_completion_tokens) |
stop | string / array | Không | Chuỗi dừng, tối đa 4 |
tools | array | Không | Định nghĩa tool (hàm), xem tool calling |
tool_choice | string / object | Không | auto / none / required / một tool cụ thể |
response_format | object | Không | {"type": "json_object"} hoặc {"type": "json_schema", ...} |
seed | integer | Không | Seed ngẫu nhiên để tái lập kết quả |
frequency_penalty | number | Không | -2.0–2.0, giảm lặp lại |
presence_penalty | number | Không | -2.0–2.0, khuyến khích chủ đề mới |
reasoning_effort | string | Không | Mức độ suy luận cho các mô hình reasoning: low / medium / high |
user | string | Không | Định danh người dùng cuối, hữu ích cho việc giám sát lạm dụng |
Cấu trúc tin nhắn
| Trường | Kiểu | Mô tả |
|---|---|---|
role | string | system / user / assistant / tool |
content | string / array | Một chuỗi, hoặc một mảng các phần đa phương thức (xem đầu vào đa phương thức) |
name | string | Tên người tham gia (tùy chọn) |
tool_calls | array | Các lệnh gọi tool do mô hình khởi tạo, nằm trong tin nhắn assistant |
tool_call_id | string | Bắt buộc trong tin nhắn tool — lệnh gọi đang được phản hồi |
Phản hồi (không stream)
{
"id": "chatcmpl-B3xK1abc123",
"object": "chat.completion",
"created": 1730000000,
"model": "deepseek-v4-1-flash-261017",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 12,
"total_tokens": 32
}
}
| Trường | Mô tả |
|---|---|
choices[].message.content | Câu trả lời của mô hình |
choices[].finish_reason | stop hoàn tất / length chạm giới hạn token / tool_calls cần thực thi tool |
usage | Lượng token sử dụng — cơ sở tính phí |
usage.completion_tokens_details.reasoning_tokens | Số token suy nghĩ trả về từ các mô hình reasoning |
Phản hồi streaming
Khi đặt "stream": true, phản hồi là một luồng sự kiện SSE:
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
Nội dung tăng dần nằm trong choices[].delta.content, kết thúc bằng data: [DONE]. Chunk cuối cùng có thể kèm usage tùy vào phía upstream.
Đầu vào đa phương thức
Truyền content dưới dạng mảng để trộn văn bản với hình ảnh/âm thanh. Hình ảnh chấp nhận một URL hoặc một data URL Base64:
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What's in this image?" },
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg"
}
}
]
}
]
}
| Loại phần nội dung | Các trường | Mô tả |
|---|---|---|
text | text | Văn bản |
image_url | image_url.url | URL hình ảnh hoặc data:image/jpeg;base64,... |
input_audio | input_audio.data / input_audio.format | Âm thanh Base64 (wav / mp3), cần mô hình có hỗ trợ |
Tool Calling
- Khai báo các tool qua
tools; mô hình phản hồi bằngtool_calls. - Thực thi các tool, thêm kết quả vào dưới dạng tin nhắn
role: "tool", rồi gọi lại.
{
"model": "deepseek-v4-1-flash-261017",
"messages": [{ "role": "user", "content": "What's the weather in Shanghai today?" }],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City name" }
},
"required": ["city"]
}
}
}
]
}
Phản hồi của mô hình:
{
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Shanghai\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}
Sau khi thực thi xong, gửi kết quả trở lại:
{
"model": "deepseek-v4-1-flash-261017",
"messages": [
{ "role": "user", "content": "What's the weather in Shanghai today?" },
{
"role": "assistant",
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\": \"Shanghai\"}" }
}
]
},
{ "role": "tool", "tool_call_id": "call_abc123", "content": "Sunny, 26°C" }
]
}
Sử dụng SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-your-token",
base_url="https://console.dotouch.ltd/v1",
)
stream = client.chat.completions.create(
model="deepseek-v4-1-flash-261017",
messages=[{"role": "user", "content": "Write a short poem about autumn"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if delta.content:
print(delta.content, end="", flush=True)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-token',
baseURL: 'https://console.dotouch.ltd/v1',
});
const stream = await client.chat.completions.create({
model: 'deepseek-v4-1-flash-261017',
messages: [{ role: 'user', content: 'Write a short poem about autumn' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
Ghi chú
Các mô hình reasoning (o-series, DeepSeek-R1, v.v.) có thể trả về phần suy nghĩ trong reasoning_content hoặc delta.reasoning_content, tùy vào kênh upstream.