Api clients / Ruby / V1 / Methods

Set Extra Header | Ruby API Client V1 (Deprecated)

This version of the Ruby API client has been deprecated in favor of the latest version of the Ruby API client.

Required API Key: no ACL required
Method signature
Algolia.set_extra_header(String headerName, String headerValue)

About this method

Sends an extra http header to Algolia, for all subsequent queries.

This method allows you to send the server a specific key/value pair - that we call an extra http header, with every query. By doing this, you are giving the api an additional header that it can later use in certain situations.

Here are some headers with different use cases:

  • Setting X-Algolia-UserToken for API key rate limiting purposes.
  • Setting X-Algolia-UserToken for analytics purposes. The Analytics API uses the provided value to distinguish between end users. It takes priority over any value in X-Forwarded-For. Use this header if you need to forward the end user’s identity without relying on IP addresses.
  • Setting X-Forwarded-For for analytics purposes. If your server sends the end-user’s IP along with every search, this enables analytics to distinguish between end-users. Otherwise, the analytics will be based on the server IP, not giving you the detail of each user. Alternatively, see X-Algolia-UserToken below.
  • Setting X-Forwarded-For for geo purposes. This ensures that the geo search location will be based on the IP of the end-user and not that of your backend server. For an example of this, see the aroundLatLngViaIP parameter.

Note that this will be replaced eventually by the “Request Options” parameter, which will allow you to set the header as part of your query parameters.


$config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('YourApplicationID', 'YourWriteAPIKey');
  'headerName => 'headerValue'

$client = \Algolia\AlgoliaSearch\SearchClient::createWithConfig($config);


type: string

Name of the header to add.

type: string

Value of the header to add.


No response.

Did you find this page helpful?