第 2/4 节课 · 6 分钟
读取响应
找到回复内容、停止原因、由谁处理以及花了多少钱。
Chat Completions 的响应如下所示(数值仅作示例):
{
"id": "G-...",
"object": "chat.completion",
"model": "openai/gpt-6-astra",
"provider": "openai",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "ok" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13,
"cost": 0.000021
}
}
choices[].message.content包含回复文本。finish_reason说明模型为什么停止:stop(正常结束)、length(达到 token 上限)、tool_calls(它想调用工具)或content_filter。model是作答的模型。如果请求由回退模型处理,这里显示的是回退模型,而不是你请求的那个。provider是处理该请求的提供商。id是 Phaseo 请求 ID。请把它记录到日志中:该请求会出现在 设置 -> 用量 -> 日志 下,联系支持时也会被要求提供它。
usage 统计 token 数量,并附带 cost:该请求以美元计的费用,也就是从你的额度中扣除的金额。在 BYOK 请求中,cost_details.upstream_inference_cost 显示你自己的提供商密钥被收取的费用;使用 Phaseo 额度时它为 null。
在 /v1/responses 上,结构有所不同:文本位于 output[].content[] 中 type 为 output_text 的项里,usage 使用 input_tokens 和 output_tokens。
检验你的理解
Chat Completions 的回复带有 finish_reason: "length"。发生了什么?
学以致用
财务部门问昨天的请求 G-01J... 花了多少钱、由哪个提供商处理。你去哪里查?
显示答案隐藏答案
在响应本身中,usage.cost 给出以美元计的费用,provider 指出由谁处理。如果你没有记录响应体,可以在 设置 -> 用量 -> 日志 下按 ID 打开该请求。
要点
从
choices 中读取回复,检查 finish_reason,并在每次调用时记录 id、model、provider 和 usage.cost。相关链接
进度保存在此浏览器中。
最后核对于 2026年11月17日