Tạo Chat Completion
Tạo phản hồi mô hình từ lịch sử hội thoại, có hỗ trợ truyền theo luồng, công cụ và thống kê sử dụng.
Dùng khóa API của bạn với Authorization: Bearer sk-xxxx.
Ví dụ yêu cầu
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}Ví dụ phản hồi
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 0,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 3,
"total_tokens": 11
}
}Ví dụ curl
curl -X POST 'https://costrouter.ai/v1/chat/completions' \
-H 'Authorization: Bearer sk-xxxx'
-H 'Content-Type: application/json'
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}'