ZBStream

Streaming Responses

Chat completions support SSE streaming via stream=true. When the model service responds with text/event-stream, ZBStream forwards the data line by line and records the request result once the stream ends.

Starting a Stream

{
  "model": "你的模型 id",
  "messages": [{ "role": "user", "content": "请逐步回答" }],
  "stream": true
}

Client Handling

  • Read data events in SSE order and close the connection at the completion marker.
  • Configure generous read timeouts on clients, reverse proxies, and gateways.
  • After a client disconnect, do not treat unreceived content as a complete answer.

Usage Recording

The service extracts token usage from the usage data embedded in the stream.