In code examples, replace
WORKSPACE_NAME with the name of your workspace. On Meilisearch Cloud, the default workspace name is cloud.Send a streaming request
Send aPOST request to the chat completions endpoint with "stream": true. Non-streaming is not yet supported and returns a 501 Not Implemented error.
-N flag in the cURL example disables output buffering, so you see each chunk as it arrives.
Understand the SSE response format
Meilisearch streams responses as Server-Sent Events (SSE) over a persistent HTTP connection. The wire format is deliberately OpenAI-compatible so you can point the official OpenAI SDKs, the Vercel AI SDK, or any other SSE-aware client at the endpoint without custom parsing. Concretely, each event on the wire follows three rules:- Every event is a line that begins with the literal prefix
data:. - The payload after
data:is a single JSON object shaped like an OpenAIchat.completion.chunk(sameid,object,choices[].deltastructure as/v1/chat/completions). - The stream terminates with the sentinel line
data: [DONE]. The[DONE]marker is a literal string, not JSON, so parsers must check for it before callingJSON.parse.
[DONE], close the reader and treat the connection as complete.
Content chunks
Regular content chunks contain the AI-generated text. Each chunk includes a small piece of the response inchoices[0].delta.content:
Tool call chunks
When you include Meilisearch tools in your request, the stream also contains tool call chunks. These appear inchoices[0].delta.tool_calls and carry search progress and source information:
End of stream
The stream ends with afinish_reason of "stop" followed by the [DONE] marker:
Handle streaming in JavaScript
Use the Fetch API to process the SSE stream in a browser or Node.js application:Maintain conversation context
The chat completions endpoint is stateless. To maintain conversation history across multiple exchanges, accumulate messages and send the full history with each request.Next steps
- Display source documents to show users where answers come from
- Configure guardrails to control response quality
- Consult the chat completions API reference for all available request parameters