Tạo chat completion (stream)
Run in Apidog
Khi được cung cấp một prompt, mô hình sẽ trả về một hoặc nhiều đoạn văn hoàn thành được dự đoán, và cũng có thể trả về xác suất của các token thay thế tại từng vị trí. Tạo phần hoàn thành dựa trên prompt và các tham số đã cung cấp. Request Provide your bearer token in the Authorization
header when making requests to protected resources. Example: Authorization: Bearer ********************
Body Params application/json
{
"model" : "claude-sonnet-4-20250514" ,
"messages" : [
{
"role" : "system" ,
"content" : "You are a helpful assistant."
} ,
{
"role" : "user" ,
"content" : "Hello!"
}
] ,
"stream" : true
} Request Code Samples
curl --location --request POST '/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "claude-sonnet-4-20250514",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"stream": true
}' Responses application/json Generate Code
{
"id" : "string" ,
"object" : "string" ,
"created" : 0 ,
"choices" : [
{
"index" : 0 ,
"message" : {
"role" : "string" ,
"content" : "string"
} ,
"finish_reason" : "string"
}
] ,
"usage" : {
"prompt_tokens" : 0 ,
"completion_tokens" : 0 ,
"total_tokens" : 0
}
} Modified at 2026-03-06 15:27:36