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

# Configure timeouts

> Change the pre-configured timeouts.

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" />

Because network connections can be unstable and slow,
the Algolia API clients have pre-configured timeouts.

<Info>
  Not all timeouts are configurable in every API client.
</Info>

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  var configuration = new SearchConfig("YourApplicationID", "YourWriteAPIKey")
  {
    ConnectTimeout = 15, // (Default) connection timeout in seconds
    ReadTimeout = 5, // (Default) read timeout in seconds
    WriteTimeout = 30, // (Default) write timeout in seconds
    HostDownDelay = 300 // 
  };
  ```

  ```go Go theme={"system"}
  config := search.Configuration{
    AppID:        "YourApplicationID",
    APIKey:       "YourWriteAPIKey",
    ReadTimeout: 5 * time.Second, // (Default) read timeout in seconds
    WriteTimeout: 30 * time.Second, // (Default) write timeout in seconds
    HostDownDelay: 5 * 60 * time.Second // (Default) delay before retrying an unavailable host, in seconds
  }

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

  ```java Java theme={"system"}
  SearchConfig configuration =
  new SearchConfig.Builder("YourApplicationID", "YourWriteAPIKey")
    .setConnectTimeOut(2000) // (Default) connection timeout in milliseconds
    .setReadTimeOut(5000) // (Default) read timeout in milliseconds
    .setWriteTimeOut(30000) // (Default) write timeout in milliseconds
    .setHostDownDelay(300000) // (Default) delay before retrying an unavailable host, in milliseconds
    .build();

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

  ```js JavaScript theme={"system"}
  const client = algoliasearch(appId, apiKey, {
    timeouts: {
      connect: 2, // (Default) connection timeout in seconds
      read: 5, // (Default) read timeout in seconds
      write: 30, // (Default) write timeout in seconds
    },
  });

  const analytics = client.initAnalytics({
    timeouts: {
      connect: 2, // (Default) connection timeout in seconds
      read: 5, // (Default) read timeout in seconds
      write: 30, // (Default) write timeout in seconds
    },
  });

  const personalization = client.initPersonalization({
    timeouts: {
      connect: 2, // (Default) connection timeout in seconds
      read: 5, // (Default) read timeout in seconds
      write: 30, // (Default) write timeout in seconds
    },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val configuration = ConfigurationSearch(
      applicationID = ApplicationID("YourApplicationID"),
      apiKey = APIKey("YourWriteAPIKey"),
      readTimeout = 50, // (Default) read timeout in seconds
      writeTimeout = 30 // (Default) write timeout in seconds
  )
  ClientSearch(configuration)
  ```

  ```php PHP theme={"system"}
  $config = SearchConfig::create('YourApplicationID', 'YourWriteAPIKey');
  $config->setConnectTimeout(2); // (Default) connection timeout in seconds
  $config->setReadTimeout(30); // (Default) read timeout in seconds
  $config->setWriteTimeout(30); // (Default) write timeout in seconds

  SearchClient::createWithConfig($config);
  ```

  ```python Python theme={"system"}
  config = SearchConfig("YourApplicationID", "YourWriteAPIKey")
  config.connect_timeout = 2  # (Default) connection timeout in seconds
  config.read_timeout = 5  # (Default) read timeout in seconds
  config.write_timeout = 30  # (Default) write timeout in seconds

  client = SearchClient.create_with_config(config)
  ```

  ```ruby Ruby theme={"system"}
  config = Algolia::Search::Config.new(
    {
      application_id: "YourApplicationID",
      api_key: "YourWriteAPIKey",
      # (Default) read timeout in seconds
      read_timeout: 30,
      # (Default) write timeout in seconds
      write_timeout: 30,
      # (Default) connection timeout in seconds
      connect_timeout: 2
    }
  )

  client = Algolia::Search::Client.create_with_config(config)
  ```

  ```scala Scala theme={"system"}
  val configuration = AlgoliaClientConfiguration(
    httpConnectTimeoutMs = 2 * 1000, // (Default) connection timeout in milliseconds
    httpReadTimeoutMs = 2 * 1000, // (Default) read timeout in milliseconds
    httpRequestTimeoutMs = 2 * 1000, // Write timeout in milliseconds
    dnsTimeoutMs = 2 * 100, // (Default) DNS connection timeout in milliseconds
    hostDownTimeoutMs = 5 * 60 * 1000 // (Default) delay before retrying an unavailable host, in milliseconds
  )
  new AlgoliaClient(applicationId, apiKey, configuration = configuration)
  ```

  ```swift Swift theme={"system"}
  let configuration = SearchConfiguration(applicationID: "YourApplicationID", apiKey: "YourWriteAPIKey")
    .set(\.readTimeout, to: 5) // (Default) read timeout in seconds
    .set(\.writeTimeout, to: 30) // (Default) write timeout in seconds

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

## Parameters

<ParamField body="connectTimeout" type="integer">
  Timeout for the TCP session to connect.

  Available in all clients **except** Swift, C#, Go, and Kotlin,

  **Default values:**

  * PHP, Ruby, JavaScript, Python, Java, and Scala: 2 seconds
  * The C# client doesn't include this timeout. It uses the native [.NET HTTP client default of 15 seconds](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.timeout?view=netcore-3.1)
</ParamField>

<ParamField body="dnsTimeout" type="integer">
  Timeout for the DNS resolution.

  Only available for Scala.
  This timeout exists as [`connectTimeout`](/#param-connecttimeout) in the other API clients.
  If both `connectTimeout` and `dnsTimeout` are set, the smaller value of the two is used.

  **Default values:**

  * Scala: 200 milliseconds
</ParamField>

<ParamField body="hostDownDelay" type="integer">
  The expected time for an unavailable host to become available.
  Affects the time between API client retries.

  Only available for C#, Java, Go, and Scala.

  **Default values:**

  * C#, Java, Go, and Scala: 5 minutes
</ParamField>

<ParamField body="readTimeout" type="integer">
  Timeout for the read on the TCP socket.

  **Default values:**

  * PHP, Ruby: 30 seconds
  * JavaScript, Python, Swift, C#, Java, and Go: 5 seconds
  * Scala: 2 seconds
  * Kotlin: 50 seconds
</ParamField>

<ParamField body="requestTimeout" type="integer">
  HTTP timeout for the request.

  Only available for Scala.

  **Default values:**

  This timeout allows you to configure a global timeout that supersedes all other timeouts.
  Since it affects all different timeouts, there's no default value.
</ParamField>

<ParamField body="searchReadTimeout" type="integer">
  Same as #{requestTimeout}, but applies only to search operations.

  Only available for Swift.

  **Default values:**

  * Swift: 5 seconds
</ParamField>

<ParamField body="writeTimeout" type="integer" default="30 s">
  Same as `requestTimeout`, but applies only to write operations.

  Available in all clients **except** Scala.

  **Default values:**

  * PHP, Ruby, JavaScript, Python, Swift, C#, Java, Go, and Kotlin: 30 seconds
</ParamField>
