You can change the default timeouts, or add extra HTTP headers to your API requests by passing options.
These API client methods support passing request options as extra key-value mappings:
We released a new version of the JavaScript API client in public beta.
Read the beta documentation for more information.
We released a new version of the PHP API client in public beta.
Read the beta documentation for more information.
We released a new version of the Java API client in public beta.
Read the beta documentation for more information.
Add HTTP headers to your requests
Adding HTTP headers to your requests lets you set parameters,
for example, a user identifier or an IP address. This can be useful
for analytics, geographical search, or to implement API key rate limits.
The Analytics API uses the value of this header to distinguish between users. It takes priority over any value in X-Forwarded-For. Use the X-Algolia-UserToken header to forward the user’s identity without relying on IP addresses.
X-Forwarded-For
For analytics in backend implementations. If your server sends the user’s IP address with every search, analytics can distinguish between users. Otherwise, the analytics uses the server’s IP address, and considers all your users as a single user.
X-Forwarded-For
For geolocation, when you perform searches from your backend. This ensures that the geolocation for a search uses the your user’s IP address and not that of your server.
$index=$client->initIndex('indexName');$res=$index->search('query string',[// Set the readTimeout to 20 seconds'readTimeout'=>20]);
1
2
3
4
5
6
7
8
index=client.init_index('indexName')request_options={# Set the read_timeout to 20 seconds'read_timeout':20}res=index.search('query string',request_options)
1
2
3
4
5
6
7
8
9
10
11
constindex=client.initIndex('indexName');constrequestOptions={// Set the readTimeout to 20 secondstimeouts:{read:20}}index.search('query string',requestOptions).then(({hits})=>{console.log(hits);});
1
2
3
4
5
6
7
8
index=client.init_index('indexName')request_options={# Set the readTimeout to 20 seconds
"readTimeout":20,}res=index.search('query string',request_options)
1
2
3
4
5
6
7
8
9
letindex=client.index(withName:"indexName")varrequestOptions=RequestOptions()// Set the readTimeout to 20 secondsrequestOptions.readTimeout=20index.search(query:"query string",requestOptions:requestOptions){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
6
7
8
9
valindexName=IndexName("indexName")valindex=client.initIndex(indexName)valquery=Query("query string")valrequestOptions=requestOptions{// Set the readTimeout to 20 secondsreadTimeout=20}index.search(query,requestOptions)
1
2
3
4
5
6
7
8
9
Indexindex=client.InitIndex("indexName");RequestOptionsrequestOptions=newRequestOptions{// Set the readTimeout to 20 secondsTimeout=20};varresult=index.Search<Result>(newQuery("query string"),requestOptions);
1
2
3
4
5
6
7
8
9
10
11
12
SearchIndex<Result>index=client.initIndex("indexName",Result.class);Queryquery=newQuery("query string");RequestOptionsrequestOptions=newRequestOptions()// Set the timeout to 20 seconds.setTimeout(20000);// SyncSearchResult<Result>search=index.search(query,requestOptions);// AsyncCompletableFuture<SearchResult<Result>>search=index.searchAsync(query,requestOptions);
1
2
3
4
5
6
7
8
// Set the readTimeout to 20 secondsctx,cancel:=context.WithTimeout(context.Background(),20*time.Second)opts:=[]interface{}{ctx,}res,err:=index.Search("query string",opts...)
Extra options
Some methods accept extra request options.
You can find them in the Parameters section for each method’s reference.