Skip to main content
Streaming returns model output in small chunks as it is generated. Use it for chat interfaces, long-form generation, agent logs, and any workflow where users should see progress immediately.

Enable streaming

Set stream to true in the request body:

Response format

Streaming responses use server-sent events. Each event starts with data: and contains a partial completion chunk:
Key points:
  • Incremental text is in choices[0].delta.content.
  • Concatenate all delta.content values in order to build the final answer.
  • The final normal chunk includes a finish_reason such as stop.
  • The stream ends with data: [DONE].

cURL example

-N disables cURL output buffering so each SSE chunk appears as soon as it arrives. Replace sk-your-key in the command with your actual key.

Python example

Replace sk-your-key in API_KEY with your actual key, then iterate over the returned stream:

Node.js example

Replace sk-your-key in API_KEY with your actual key:

When to use streaming

Next steps