Skip to main content
Streaming lets your application display model output token-by-token as it is generated rather than waiting for the complete response. This dramatically improves perceived latency and gives users immediate feedback — particularly valuable for conversational interfaces, long-form generation, and anything where time-to-first-token matters. Meliai’s streaming implementation follows the OpenAI server-sent events (SSE) protocol, so any client already using OpenAI streaming works without modification.

Enabling Streaming

Set stream: true in your request body to switch from a single JSON response to a stream of SSE events. The OpenAI SDK handles the underlying SSE protocol for you, exposing each chunk as an iterable object.

SSE Format

When streaming is enabled, Meliai sends the response as a sequence of server-sent events over the HTTP connection. Each event is a line prefixed with data: followed by a JSON object. The stream is terminated by the special sentinel data: [DONE]. A single chunk looks like this:
The final chunk before data: [DONE] will have finish_reason set to "stop" (or another stop reason) and an empty delta.content. If you are parsing the raw SSE stream yourself, skip any line that does not start with data: and stop processing when you encounter data: [DONE].

Getting Usage in Streaming Mode

By default, token usage is not included in streaming responses. To receive a final chunk containing prompt and completion token counts, set stream_options.include_usage to true.
Python
The usage chunk arrives after the finish_reason chunk and before data: [DONE]. Its choices array is empty, and it carries a populated usage field identical in structure to a non-streaming response.
Add the :speed routing suffix to your model ID — for example mistral-small:speed — to bias routing toward the lowest-latency European provider. This reduces time-to-first-token for interactive streaming applications without changing your code.