API chat completions
Cách gọi model chat qua endpoint /chat/completions chuẩn OpenAI: định dạng request, streaming, tool call và cache prompt.
Chat
POST /chat/completions nhận nguyên request của OpenAI: messages, max_tokens, temperature, top_p, stop, tools và tool_choice, response_format, stream. Trường lạ được chuyển tới model. Mọi response đều có header x-request-id; hãy gửi kèm khi liên hệ hỗ trợ.
Streaming
Đặt "stream": true để nhận server-sent events. Thêm "stream_options": {"include_usage": true} để có số token ở chunk cuối.
{
"model": "deepseek-v4-1-flash",
"stream": true,
"stream_options": { "include_usage": true },
"messages": [{ "role": "user", "content": "Hello" }]
}Cache prompt
Phần đầu prompt lặp lại (system prompt, tài liệu dài, lịch sử chat) được nhà cung cấp cache. Token input trúng cache tự động tính giá rẻ hơn. Hãy đặt phần cố định ở đầu prompt và giữ nguyên.
