---
title: "Configuring xConnect Client API timeouts"
slug: "configuring-xconnect-client-api-timeouts"
abstract: "How to configure default and per-request timeouts for the xConnect Client API, both in a Sitecore and non-Sitecore context."
---
# Configuring xConnect Client API timeouts

You can set a default timeout when you instantiate the xConnect Client API or you can set a timeout for a particular request.

> [!note]
> You can also [configure timeouts at a storage provider level](https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-platform/configuring-the-xconnect-service.html "Configuring the xConnect service").

<details>
<summary><h2>Set the default client timeout in a non-Sitecore context</h2></summary>

In a non-Sitecore context, default client timeout can be set by passing in a `TimeoutHttpClientModifier`. In the following example, a timeout modifier is added to the search, collection, and configuration clients before the configuration is initialized:

```csharp
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Schema;
using System;
using System.Threading.Tasks;
using Sitecore.XConnect.Client.WebApi;
using Sitecore.Xdb.Common.Web;
using Sitecore.XConnect.Collection.Model;
using System.Collections.Generic;

namespace Symposium.xConnect.Course
{
    public class Program
    {
        private static void Main(string[] args)
        {
            MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
        }

        private static async Task MainAsync(string[] args)
        {
            CertificateWebRequestHandlerModifierOptions options =
            CertificateWebRequestHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=15E6693B0AECB63DE57D991EC363CA462DC52432");

            var certificateModifier = new CertificateWebRequestHandlerModifier(options);

            List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
            var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(200));
            clientModifiers.Add(timeoutClientModifier);

            var collectionClient = new CollectionWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var searchClient = new SearchWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var configurationClient = new ConfigurationWebApiClient(new Uri("https://sc900rev170622_xconnect/configuration"), clientModifiers, new[] { certificateModifier });

            var cfg = new XConnectClientConfiguration(
                new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);

            try
            {
                await cfg.InitializeAsync();

            }
            catch (XdbModelConflictException ce)
            {
                Console.WriteLine("ERROR:" + ce.Message);
                return;
            }

            using (var client = new XConnectClient(cfg))
            {
            }
        }
    }
}

```

> [!note]
> If you do not specify a client timeout, the [default client timeout is 100 seconds](https://msdn.microsoft.com/en-us/library/system.net.http.httpclient\(v=vs.110\).aspx).

</details>

<details>
<summary><h2>Set the default client timeout in a Sitecore context</h2></summary>

There is no default client timeout for the xConnect Client API in a Sitecore context. This is because different features within the platform have different timeout requirements. For example, the tracker must time out quickly if a contact is not available whereas the List Manager must allow time for large batches to be processed.

</details>

<details>
<summary><h2>Specify a timeout per request</h2></summary>

You can specify a timeout per request by passing in a cancellation token. All extension methods on the client have an overload that accepts a cancellation token:

```

// GET
var cancellationTokenSource = new CancellationTokenSource(200);
Task<Contact> contactTask = client.GetAsync<Contact>(reference, new ContactExpandOptions() { }, cancellationTokenSource.Token);

// SUBMIT
var cancellationTokenSource1 = new CancellationTokenSource(200);
await client.SubmitAsync(cancellationTokenSource1.Token);

// GETBATCHENUMERATOR
var results = await client.Contacts.Where(f => f.IsKnown == true).GetBatchEnumerator(10, cancellationTokenSource.Token);

// TOSEARCHRESULTS
var results = await client.Contacts.Where(f => f.IsKnown == true).ToSearchResults(cancellationTokenSource.Token);

```

> [!tip]
> If you are using the synchronous extension methods, you can pass in a `TimeSpan`.

</details>