Prerequisites
Before starting, ensure you have:- A secure Meilisearch >= v1.15.1 project
- An API key from an LLM provider
- At least one index with searchable content
Enable the chat completions feature
First, enable the chat completions experimental feature:Find your chat API key
When Meilisearch runs with a master key on an instance created after v1.15.1, it automatically generates a “Default Chat API Key” withchatCompletions
and search
permissions on all indexes. Check if you have the key using:
/chats
endpoint.
Troubleshooting: Missing default chat API key
If your instance does not have a Default Chat API Key, create one manually:Configure your indexes for chat
Each index that you want to be searchable through chat needs specific configuration:The
description
field helps the LLM understand what data is in the index, improving search relevance.Configure a chat completions workspace
Create a workspace with your LLM provider settings. Here are examples for different providers:Send your first chat completions request
Now you can start a conversation. Note the-N
flag for handling streaming responses:
tools
array. These settings are optional, but greatly improve user experience:
_meiliSearchProgress
: shows users what searches are being performed_meiliSearchSources
: displays the actual documents used to generate responses
Build a chat interface using the OpenAI SDK
Since Meilisearch’s chat endpoint is OpenAI-compatible, you can use the official OpenAI SDK:Error handling
When using the OpenAI SDK with Meilisearch’s chat completions endpoint, errors from the streamed responses are natively handled by OpenAI. This means you can use the SDK’s built-in error handling mechanisms without additional configuration:Troubleshooting
Common issues and solutions
Empty reply from server (curl error 52)
Causes:- Meilisearch not started with a master key
- Experimental features not enabled
- Missing authentication in requests
- Restart Meilisearch with a master key:
meilisearch --master-key yourKey
- Enable experimental features (see setup instructions above)
- Include Authorization header in all requests
”Invalid API key” error
Cause: Using the wrong type of API key Solution:- Use either the master key or the “Default Chat API Key”
- Don’t use search or admin API keys for chat endpoints
- Find your chat key:
curl http://localhost:7700/keys -H "Authorization: Bearer MEILISEARCH_KEY"
”Socket connection closed unexpectedly”
Cause: Usually means the OpenAI API key is missing or invalid in workspace settings Solution:-
Check workspace configuration:
-
Update with valid API key:
Chat not searching the database
Cause: Missing Meilisearch tools in the request Solution:- Include
_meiliSearchProgress
and_meiliSearchSources
tools in your request - Ensure indexes have proper chat descriptions configured
”stream: false is not supported” error
Cause: Trying to use non-streaming responses Solution:- Always set
"stream": true
in your requests - Non-streaming responses are not yet supported
Next steps
- Explore advanced chat API features
- Learn about conversational search concepts
- Review security best practices