黑马天启 · 多模型 Token 平台

流式输出(Streaming)

开关方式

{"model": "deepseek-flash", "messages": [...], "stream": true}

事件格式(OpenAI 兼容)

data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"你"}}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"好"}}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop"}],"usage":{...}}
data: [DONE]
  • 需要计费用量时请传 "stream_options": {"include_usage": true}
  • 首字延迟(TTFT)与模型能力、网络、上游负载相关

失败与重试语义

平台保证:

只有在客户端还没有收到模型正文之前,才允许切换到备用通道
一旦已经开始向客户端输出内容,就不会重新请求另一个通道并续接结果

这样可以避免重复内容、重复计费与无法解释的账单。

服务端代理配置要点

proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 3600s;