This page documents an earlier version of the API client. For the latest version, see Generate secured API key.
add_api_key
or update_api_key
methods of an API client.
Secured API keys must have stricter permissions than their base API key.
If you use the same permissions and restrictions as the base API key,
using this key generates a
403
status error.Examples
Generate a secured API key containing a filter
Generate a secured API key with an expiration date
Generate a secured API key with indices restriction
Generate a secured API key with a network restriction
Generate a secured API key with rate-limiting applied per user
Parameters
The search-only API key that the secured API key will inherit its restrictions from.
Filters that apply to every search made with the secured API key.
You can add extra filters at search time with the
filters
parameter.For example, if you set the filter group:admin
on your generated API key, and you add groups:press OR groups:visitors
with the filters
query parameter, your final search filter is equivalent to groups:admin AND (groups:press OR groups:visitors)
.Index names that can be queried.
By default, all indices are queried.
IPv4 network allowed to use the generated key. Use this to protect against API key leaking and reuse.You can only provide a single source, but you can specify a range of IPs (for example,
192.168.1.0/24
).Search parameters applied at query time.If you specify any of the following parameters in both the API key (
A
) and in your search (B
),
they are combined (A AND B
):Unique user IP address.This can be useful when you want to impose a rate limit on specific users. By default, rate limits are set based on the IP address. This can become an issue when several users search from the same IP address. To avoid this, you can set a unique
userToken
for each user when generating their API key. This lets you restrict each user to a maximum number of API calls per hour, even if they share their IP with another user.Specifying the userToken
in a secured API key is also a good security practice as it ensures users don’t change it.
Many features like Analytics, Personalization, and Dynamic Re-ranking rely on the authenticity of user identifiers.
Setting the userToken
at the API key level ensures that downstream services work as expected and prevents abuse.Unix timestamp used to set the expiration date of the API key.
Response
The generated API key.
Response as JSON
This section shows the JSON response returned by the API. Each API client wraps this response in language-specific objects, so the structure may vary. To view the response, use thegetLogs
method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.
JSON