Skip to main content

Overview

Add "stream": true to any chat completion request to receive tokens as they’re generated instead of waiting for the full response. Uses the Server-Sent Events (SSE) protocol — the same format as OpenAI.

Code Examples

SSE Event Format

Each streamed chunk arrives as a data: line:
The stream ends with data: [DONE].

Vercel AI SDK

Works perfectly with the Vercel AI SDK for Next.js and React:

LangChain Streaming

All models that support chat completions support streaming. Just set stream: true.

Overview

Set stream: true to receive tokens as they are generated instead of waiting for the full response. Samurai AI uses the OpenAI-compatible SSE format.

Code Examples

SSE Format

Each chunk is a data: line containing a JSON object:
The stream ends with data: [DONE].

Vercel AI SDK

All models that support chat completions also support streaming. Use the same model parameter.