Skip to main content
Searching directly from the frontend significantly improves search response time, and reduces load and traffic on your servers.

Generate search keys

For client-side implementations, always use a Search-only API key. Your Admin API key is sensitive. You should never share it with anyone and it must remain confidential. To generate a search key for a given index, use the SearchClient’s generateSecuredApiKey method.
Store your search-only API key in your environment variables, or generate a new one using the Clients’ addApiKey method.
PHP
$searchOnlyAPIKey = getenv('ALGOLIA_SEARCH_ONLY_KEY');
$validUntil = time() + 3600;

// Generate a new secured API key
$searchKey = \Algolia\AlgoliaSearch\SearchClient::generateSecuredApiKey(
  $searchOnlyAPIKey,
  [
    'restrictIndices' => $this->searchService->searchableAs(Post::class),
    'validUntil' => $validUntil
  ]
);
Define the indices you want to access with this API key, and change the validUntil parameter to set a validity period.

Integration with InstantSearch

Now that you know how to generate your secured API keys, you can use them to create your frontend view with InstantSearch. To learn more, see What is InstantSearch?.
⌘I