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. Each event is a line prefixed withdata: followed by a JSON object. The stream ends with a data: [DONE] message.
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