跳转到主要内容

聊天完成对象

/v1/chat/completions 非流式返回 chat.completion,流式返回 chat.completion.chunk 本文页保留的是 Crazyrouter 当前 OpenAI 兼容返回里最稳定、最通用的结构认知。

非流式对象

当前生产最小请求示例:
cURL
curl https://crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {
        "role": "user",
        "content": "Explain what a REST API is in one sentence."
      }
    ],
    "max_tokens": 64
  }'
当前生产返回的典型骨架:
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1774177466,
  "model": "gpt-5.4",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "...",
        "reasoning_content": null,
        "tool_calls": null
      },
      "finish_reason": "stop"
    }
  ]
}

应该这样理解

  • message.content 是最终文本输出
  • message.tool_calls 只在模型请求工具时出现
  • message.reasoning_content 在某些模型或某些路由下可能出现,但当前不应把它当成稳定必有字段

流式对象

流式请求时,服务器通过 SSE 逐块返回 chat.completion.chunk
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion.chunk",
  "created": 1774177466,
  "model": "gpt-5.4",
  "choices": [
    {
      "index": 0,
      "delta": {
        "role": "assistant",
        "content": "..."
      },
      "finish_reason": null
    }
  ]
}
常见 SSE 形态:
data: {"object":"chat.completion.chunk",...}
data: {"choices":[{"delta":{"content":"..."}}],...}
data: [DONE]

常看字段

字段说明
object非流式是 chat.completion,流式是 chat.completion.chunk
model实际返回所使用的模型名
choices[].message.content非流式最终文本
choices[].message.tool_calls非流式工具调用
choices[].delta.content流式增量文本
choices[].finish_reason停止原因,如 stoplengthtool_calls
上游模型可能会透传额外字段。写客户端时应优先依赖稳定的通用字段,不要假设每个模型都暴露相同的扩展字段。