API/chat/completions
REST API cho hội thoại, suy luận, gọi công cụ và streaming. Codex, OpenCode, Kimi CLI và Grok CLI đều dùng endpoint này.
https://api.ltnproxy.com/v1/chat/completionsAuthorization: Bearer sk-your_api_keyBắt buộc có model và messages. Lấy id của mô hình từ GET /v1/models.
curl "https://api.ltnproxy.com/v1/chat/completions" \
-H "Authorization: Bearer sk-your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Tóm tắt lợi ích của một API hợp nhất."}]
}'Đặt stream: true để nhận từng chunk qua Server-Sent Events. Luồng kết thúc bằng data: [DONE].
curl --no-buffer "https://api.ltnproxy.com/v1/chat/completions" \
-H "Authorization: Bearer sk-your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.1-sol",
"stream": true,
"messages": [{"role": "user", "content": "Gợi ý năm tên sản phẩm cho một ứng dụng AI."}]
}'Khai báo công cụ trong tools. Mô hình trả lời bằng tool_calls, bạn chạy hàm rồi gửi kết quả lại dưới dạng một message có role: "tool".
{
"model": "gpt-6.1-sol",
"messages": [{"role": "user", "content": "Hôm nay thời tiết ở Hà Nội thế nào?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Lấy thời tiết hiện tại của một thành phố",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
}
]
}