Skip to main content
Streaming returns the reply token by token over Server-Sent Events (SSE): a long-lived HTTP response where each message begins with data:. The SDKs handle the framing.

Turn It On

Set stream: true on the same chat request:
-N turns off curl’s buffering so tokens show as they arrive.

The Stream

  • New text is in choices[0].delta.content. Concatenate the chunks to rebuild the reply.
  • delta.role: "assistant" appears once, on the first chunk that carries content or reasoning.
  • The last content chunk sets finish_reason: stop, length, tool_calls, or error.
  • data: [DONE] ends the stream. It is not JSON.
  • : keep-alive comment lines can appear. Ignore them.

Usage

Usage is known only when generation finishes. Ask for it:
One extra chunk with an empty choices array and a usage object arrives before data: [DONE].

Mid-Stream Errors

Once the stream starts, HTTP 200 is already sent. A later failure arrives as a final chunk with a top-level error object, an empty delta, and finish_reason: "error", and the stream ends without data: [DONE]. Check each chunk for error as well as the status. A failure before any byte is written returns an ordinary HTTP error.

Stream Format Reference

Every chunk field.

Make Your First Request

Non-streaming.

Tool Call Streaming

Tool calls in fragments.