> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set extra header

> Send an extra HTTP header to Algolia for use with later queries.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Request options" href="/doc/libraries/sdk/request-options" />

This method lets you send the server a specific key-value pair (an **extra HTTP header**) with every query. This gives the API an additional header it can use in situations such as:

* Setting `X-Forwarded-For` for analytics. If your server sends the user's IP address with every search, analytics can distinguish between users. Otherwise, analytics uses the server's IP address, which doesn't provide user details. Alternatively, see the following `X-Algolia-UserToken` example.
* Setting `X-Algolia-UserToken` for analytics. The Analytics API uses the provided value to distinguish between users. It takes priority over any value in `X-Forwarded-For`. Use this header if you need to forward the user's identity without relying on IP addresses.
* Setting `X-Algolia-UserToken` for [API key rate limiting](/doc/guides/security/api-keys/in-depth/api-key-restrictions#rate-limit).
* Setting `X-Forwarded-For` to ensure that geo-search locations use the user's IP address, not your backend server's. For an example of this, see the [`aroundLatLngViaIP`](/doc/api-reference/api-parameters/aroundLatLngViaIP) parameter.

<Info>
  The `set extra header` method will eventually be replaced by the request options parameter, allowing you to set the header as part of your query parameters.
</Info>

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  var configuration = new SearchConfig("YourApplicationID", "YourWriteAPIKey");
  configuration.DefaultHeaders.Add("NAME-OF-HEADER", "value-of-header");

  SearchClient client = new SearchClient(configuration);
  ```

  ```go Go theme={"system"}
  config := search.Configuration{
    AppID:  "YourApplicationID",
    APIKey: "YourWriteAPIKey",
    Headers: map[string]string{
      "NAME-OF-HEADER": "value-of-header",
    },
  }

  client := search.NewClientWithConfig(config)
  ```

  ```java Java theme={"system"}
  SearchConfig configuration =
  new SearchConfig.Builder("YourApplicationID", "YourWriteAPIKey")
    .addExtraHeaders("NAME-OF-HEADER", "value-of-header")
    .build();

  SearchClient client = DefaultSearchClient.create(configuration);
  ```

  ```js JavaScript theme={"system"}
  const client = algoliasearch('YourApplicationID', 'YourWriteAPIKey', {
    headers: {
      'NAME-OF-HEADER': 'value-of-header'
    }
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val configuration = ConfigurationSearch(
      applicationID = ApplicationID("YourApplicationID"),
      apiKey = APIKey("YourWriteAPIKey"),
      defaultHeaders = mapOf("NAME-OF-HEADER" to "value-of-header")
  )
  ClientSearch(configuration)
  ```

  ```php PHP theme={"system"}
  $config = \Algolia\AlgoliaSearch\Config\SearchConfig::create('YourApplicationID', 'YourWriteAPIKey');
  $config->setDefaultHeaders([
    'headerName' => 'headerValue'
  ]);

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

  ```python Python theme={"system"}
  config = SearchConfig('YourApplicationID', 'YourWriteAPIKey')
  config.headers['NAME-OF-HEADER'] = 'value-of-header'

  client = SearchClient.create_with_config(config)
  ```

  ```ruby Ruby theme={"system"}
  config = Algolia::Search::Config.create('YourApplicationID', 'YourWriteAPIKey')
  config.headers['NAME-OF-HEADER'] = 'value-of-header'
  ```

  ```scala Scala theme={"system"}
  val client = new AlgoliaClient(
    "YourApplicationID",
    "YourWriteAPIKey",
    customHeader = Map(
      "NAME-OF-HEADER" -> "value-of-header"
    )
  )
  ```

  ```swift Swift theme={"system"}
  let configuration = SearchConfiguration(applicationID: "YourApplicationID", apiKey: "YourWriteAPIKey")
    .set(\.defaultHeaders, to: ["NAME-OF-HEADER": "value-of-header"])

  let client = SearchClient(configuration: configuration)
  ```
</CodeGroup>

## Parameters

<ParamField body="headerName" type="string" required>
  Name of the header to add.
</ParamField>

<ParamField body="headerValue" type="string" required>
  Value of the header to add.
</ParamField>
