SSE Response Format

This document describes the runtime SSE data format returned by POST /v1/chat/completions.

Event Envelope

Each SSE chunk is sent as:

data: <json>

The JSON body follows an OpenAI-style chat completion chunk.

Chunk Schema

Field Type Description
id string Stream id, typically stream:chat:<uuid>
object string Always chat.completion
created number Unix timestamp
model string Model name (may be empty string)
choices array Completion chunks
usage `object \ undefined` Optional usage payload
error `object \ undefined` Error payload (when request fails)

choices[0] fields

Field Type Description
index number Always 0 for current implementation
delta.content `string \ undefined` Text delta
delta.tool_calls `array \ undefined` Tool call delta list
finish_reason `null \ "stop" \ "tool_calls"` End reason

Typical Stream Flow

  1. Zero or more chunks with finish_reason: null.
  2. Final chunk with finish_reason: "stop" or "tool_calls".
  3. Server closes the HTTP response.

Example: Text Stream

data: {"id":"stream:chat:1","object":"chat.completion","created":1773042793,"model":"","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"stream:chat:1","object":"chat.completion","created":1773042794,"model":"","choices":[{"index":0,"delta":{"content":" world"},"finish_reason":null}]}

data: {"id":"stream:chat:1","object":"chat.completion","created":1773042795,"model":"","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}]}

Example: Tool Call Stream

data: {"id":"stream:chat:2","object":"chat.completion","created":1773042793,"model":"","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"call_1","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"Singapore\"}"}}]},"finish_reason":null}]}

data: {"id":"stream:chat:2","object":"chat.completion","created":1773042794,"model":"","choices":[{"index":0,"delta":{"content":""},"finish_reason":"tool_calls"}]}

Completion Detection

Treat the stream as completed when:

  • A chunk has choices[0].finish_reason equal to stop or tool_calls, and/or
  • The HTTP connection is closed by the server.

Do not rely on data: [DONE] in this endpoint.

results matching ""

    No results matching ""