stream 设置为 true 后,服务会通过 Server-Sent Events 逐段返回内容。Responses 使用带 type 的事件;Chat Completions 使用 choices[].delta 数据块,两种消费者不能混用。
- Responses(新项目)
- Chat Completions(兼容客户端)
response.created、response.output_text.delta、response.completed 和 error。客户端处理
- 不要假设每个数据块都包含文本。
- 正确处理结束标记和连接中断。
- 不要对同一条流式请求自动无限重连,否则可能重复计费。
- 前端断开时,服务端应中止上游请求。
- 工具调用参数可能跨多个事件或数据块返回,需要按当前协议拼接并通过
call_id或工具调用 ID 关联。