In code examples, replace
WORKSPACE_NAME with the name of your workspace. On Meilisearch Cloud, the default workspace name is cloud.Streaming is required
All requests to the chat completions endpoint must include"stream": true. Non-streaming (stream: false) is not yet supported and returns a 501 Not Implemented error.
Send a streaming request
Send aPOST request to /chats/{workspace}/chat/completions with stream: true:
Meilisearch tools
Meilisearch provides three special tools that improve the chat experience. Declare them in thetools array of your request and Meilisearch intercepts them — they are never forwarded to the LLM provider.
| Tool | Purpose |
|---|---|
_meiliSearchProgress | Reports what searches are being performed in real time |
_meiliSearchSources | Returns the documents used by the LLM to formulate its answer |
_meiliAppendConversationMessage | Asks the client to append internal tool calls and results to the conversation history |
call_id field links _meiliSearchProgress and _meiliSearchSources events together: both carry the same call_id, allowing you to associate a search query with the documents it returned.
_meiliAppendConversationMessage is the key to multi-turn conversations. Since the endpoint is stateless, Meilisearch uses this tool to expose the internal search tool calls and their results back to the client. You must push these messages into your messages array before the next request, or the LLM will lose the context from previous searches and produce lower-quality answers.
Tool schemas
Complete example: progress, sources, and history
The following example combines all three tools and demonstrates the full recommended usage: streaming progress, displaying sources, and maintaining conversation history for multi-turn questions.JavaScript (Fetch)
Troubleshooting
Empty reply from server (curl error 52)
Causes:- Chat completions feature not enabled
- Missing authentication in requests
- Enable the feature (see setup guide)
- Include the
Authorizationheader in all requests
”Invalid API key” error
Cause: Using the wrong type of API key Solution:- Use the “Default Chat API Key”
- Do not use search or admin API keys for chat endpoints
- Find your chat key with the list keys endpoint
”Socket connection closed unexpectedly”
Cause: Usually means the LLM provider API key is missing or invalid in workspace settings Solution:-
Check workspace configuration:
-
Update with a valid API key:
No search progress visible
Cause: The_meiliSearchProgress tool is not declared in the request
Solution:
The search still runs and the LLM still answers, but without _meiliSearchProgress you receive no visibility into what searches are being performed. Add all three Meilisearch tools to your request as shown in the complete example.
Next steps
One-shot summarization
Generate single AI answers without conversation history.
Stream chat responses
Handle streaming responses for a real-time experience.
Display source documents
Show users which documents were used to generate responses.
Configure guardrails
Restrict AI responses to topics covered by your data.
Chat completions API reference
Full reference for the chat completions endpoint.
Reduce hallucination
Techniques to keep AI responses grounded in your data.