聊天完成对象
chat.completion 对象是调用 Chat Completions API 后非流式返回的结果格式。
对象示例
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么我可以帮你的?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 12,
"total_tokens": 27
}
}
字段说明
| 字段 |
类型 |
说明 |
id |
string |
本次请求的唯一 ID |
object |
string |
固定为 "chat.completion" |
created |
integer |
创建时间(Unix 时间戳) |
model |
string |
实际使用的模型 ID |
choices |
array |
模型生成的结果列表 |
choices[].index |
integer |
结果索引(从 0 开始) |
choices[].message.role |
string |
固定为 "assistant" |
choices[].message.content |
string |
模型生成的文本内容 |
choices[].finish_reason |
string |
结束原因:stop / length / tool_calls |
usage.prompt_tokens |
integer |
输入 Token 数 |
usage.completion_tokens |
integer |
输出 Token 数 |
usage.total_tokens |
integer |
总 Token 数 |
finish_reason 枚举值
| 值 |
说明 |
stop |
模型自然停止生成 |
length |
达到 max_tokens 限制 |
tool_calls |
模型调用了工具 |
content_filter |
内容被安全过滤 |