curl \
-X POST 'MEILISEARCH_URL/keys' \
-H 'Authorization: Bearer MASTER_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"description": "Add documents: Products API key",
"actions": ["documents.add"],
"indexes": ["products"],
"expiresAt": "2042-04-02T00:42:42Z"
}'{
"uid": "01b4bc42-eb33-4041-b481-254d00cce834",
"key": "d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4",
"name": "Indexing Products API key",
"description": null,
"actions": [
"documents.add"
],
"indexes": [
"products"
],
"expiresAt": "2021-11-13T00:00:00Z",
"createdAt": "2021-11-12T10:00:00Z",
"updatedAt": "2021-11-12T10:00:00Z"
}{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
"type": "auth",
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
}Create API key
Create a new API key with the specified name, description, actions, and index scopes. The key value is returned only once at creation time; store it securely.
Required fields: actions, indexes, expiresAt.
Optional fields: name, description, uid.
Set expiresAt to null to create a key that never expires.
Use "*" in the actions array to grant all permissions (not recommended for production).
Use ["*"] in the indexes array to grant access to all indexes.
curl \
-X POST 'MEILISEARCH_URL/keys' \
-H 'Authorization: Bearer MASTER_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"description": "Add documents: Products API key",
"actions": ["documents.add"],
"indexes": ["products"],
"expiresAt": "2042-04-02T00:42:42Z"
}'{
"uid": "01b4bc42-eb33-4041-b481-254d00cce834",
"key": "d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4",
"name": "Indexing Products API key",
"description": null,
"actions": [
"documents.add"
],
"indexes": [
"products"
],
"expiresAt": "2021-11-13T00:00:00Z",
"createdAt": "2021-11-12T10:00:00Z",
"updatedAt": "2021-11-12T10:00:00Z"
}{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
"type": "auth",
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
}Authorizations
An API key is a token that you provide when making API calls. Read more about how to secure your project.
Include the API key to the Authorization header, for instance:
-H 'Authorization: Bearer 6436fc5237b0d6e0d64253fbaac21d135012ecf1'
If you use a SDK, ensure you instantiate the client with the API key, for instance with JS SDK:
const client = new MeiliSearch({
host: 'MEILISEARCH_URL',
apiKey: '6436fc5237b0d6e0d64253fbaac21d135012ecf1'
});
Body
A list of actions permitted for the key. ["*"] for all actions. The
* character can be used as a wildcard when located at the last
position. e.g. documents.* to authorize access on all documents
endpoints.
Valid actions include: search, documents.add,
documents.get, documents.delete, indexes.create, indexes.get,
indexes.update, indexes.delete, indexes.swap, tasks.get,
tasks.cancel, tasks.delete, settings.get, settings.update,
stats.get, dumps.create, snapshots.create, version, keys.get,
keys.create, keys.update, keys.delete. Use * to grant all actions.
*, search, documents.*, documents.add, documents.get, documents.delete, indexes.*, indexes.create, indexes.get, indexes.update, indexes.delete, indexes.swap, tasks.*, tasks.cancel, tasks.delete, tasks.get, settings.*, settings.get, settings.update, stats.*, stats.get, metrics.*, metrics.get, dumps.*, dumps.create, snapshots.*, snapshots.create, version, keys.create, keys.get, keys.update, keys.delete, experimental.get, experimental.update, export, network.get, network.update, chatCompletions, chats.*, chats.get, chats.delete, chatsSettings.*, chatsSettings.get, chatsSettings.update, *.get, webhooks.get, webhooks.update, webhooks.delete, webhooks.create, webhooks.*, indexes.compact, fields.post, tasks.compact, dynamicSearchRules.get, dynamicSearchRules.create, dynamicSearchRules.update, dynamicSearchRules.delete, dynamicSearchRules.* ["documents.add"]
Response
Key has been created.
Represents an API key used for authenticating requests to Meilisearch. Each key has specific permissions defined by its actions and can be scoped to particular indexes. Keys provide fine-grained access control for your Meilisearch instance.
The list of actions (permissions) this key is allowed to perform.
Examples include documents.add, search, indexes.create,
settings.update, etc. Use * to grant all permissions.
*, search, documents.*, documents.add, documents.get, documents.delete, indexes.*, indexes.create, indexes.get, indexes.update, indexes.delete, indexes.swap, tasks.*, tasks.cancel, tasks.delete, tasks.get, settings.*, settings.get, settings.update, stats.*, stats.get, metrics.*, metrics.get, dumps.*, dumps.create, snapshots.*, snapshots.create, version, keys.create, keys.get, keys.update, keys.delete, experimental.get, experimental.update, export, network.get, network.update, chatCompletions, chats.*, chats.get, chats.delete, chatsSettings.*, chatsSettings.get, chatsSettings.update, *.get, webhooks.get, webhooks.update, webhooks.delete, webhooks.create, webhooks.*, indexes.compact, fields.post, tasks.compact, dynamicSearchRules.get, dynamicSearchRules.create, dynamicSearchRules.update, dynamicSearchRules.delete, dynamicSearchRules.*