The API client methods accept additional parameters for adding custom headers or query parameters, or for changing the default timeouts for individual requests.

To customize all requests, you can customize the client.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from algoliasearch.search.client import SearchClientSync

client = SearchClientSync(
        app_id="ALGOLIA_APPLICATION_ID",
        api_key="ALGOLIA_API_KEY"
)

results = client.search_single_index(
    index_name="ALGOLIA_INDEX_NAME",
    search_params={"query": "time"},
    request_options={
        # Add extra header
        "headers": {
            "extra-header": "greetings",
        },
        # Add query parameter
        "query_parameters": {
            "queryParam": "value",
        },
        # Change default timeouts
        "timeouts": {
            "read": 10_000,
            "connect": 10_000,
        },
    }
)

Reference

headers
type: dict[str,str]

Additional headers as key-value pairs to send with this request.

query_parameters
type: dict[str,Any]

Additional query parameters to send with this request. They only take effect with API operations that support query parameters. Otherwise, they’re ignored.

timeouts
type: dict[str, int]

Timeouts for read and write operations, in milliseconds. You can change the following timeouts:

  • connect. Maximum number of milliseconds to wait for the connection to be established (default: 5,000 ms).
  • read. Maximum number of milliseconds to wait for a response from the server (for GET requests, default: 5,000 ms).
  • write. Maximum number of milliseconds to wait for a response from the server (for requests other than GET, default: 5,000 ms).
Did you find this page helpful?
Python API clients v4