Chat Completions Streaming
Setstream: true in your request body to enable SSE output. Add stream_options: {"include_usage": true} to receive a final token-count chunk before the [DONE] sentinel.
data: lines, each containing a JSON chunk:
Responses Endpoint Streaming
ThePOST /v1/responses endpoint emits structured named events instead of generic chat.completion.chunk objects. Each SSE line includes both an event: field and a data: field. This format maps closely to the OpenAI Responses API event schema.
The full event sequence for a streaming response looks like this:
response.completed event includes the full usage object — you do not need a separate stream_options flag on the responses endpoint.
Streaming Error Handling
Errors that occur mid-stream arrive as adata: event with an error key — not as an HTTP error status code. Your SSE parser must check for this shape on every chunk:
Streaming Tool Calls
When a model returns a tool call during a streamed response, thefunction.arguments field arrives as a sequence of fragments across multiple chunks. You must accumulate all fragments before calling JSON.parse — individual chunks are not valid JSON on their own.
Piramyd’s tool call integrity feature automatically buffers argument deltas and emits a single validated chunk, so the JSON you receive is always complete and well-formed. You still need to accumulate across chunks, but you will not receive truncated or malformed JSON.
