Streaming
零派智能API 支持 SSE(Server-Sent Events)流式响应,适用于 Chat Completions 和 Responses 接口。流式模式下,模型逐 token 返回内容,实现实时输出效果。
stream 参数
在请求体中将 stream 设置为 true 即可启用流式响应:
{ "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "写一首关于秋天的诗" } ], "stream": true}SSE 格式
流式响应使用 SSE 格式,每条消息以 data: 前缀开头,以两个换行符分隔:
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1699999999,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1699999999,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"content":"秋"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1699999999,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{"content":"风"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","created":1699999999,"model":"gpt-4o-mini","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]