---
title: "Configure request timeouts"
slug: "configure-request-timeouts"
abstract: "How to configure global and per-request timeouts for Marketplace SDK requests."
---

# Configure request timeouts

You can configure how long your Marketplace app waits for an SDK request to complete. This is useful when an operation, such as generating a brand review, takes longer than the default timeout.

The SDK supports two timeout levels:

- *Global timeout* - set `timeout` when initializing the client.
- *Per-request timeout* - set `timeoutMs` for an individual request. It overrides the global timeout without changing the timeout for other requests.

All timeout values are in milliseconds.

> [!note]
> **Before you begin**
>
> - Complete an [SDK quick start](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/quick-starts.html "Quick starts").
> - For the client-side examples, [initialize the `xmc` package](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/initialize-the-xmc-package.html "Initialize the xmc package").
> - For server-side requests, use a [full-stack app with custom authorization](https://doc.sitecore.com/mp/en/developers/marketplace/app-architecture-and-authorization-options.html). The server-side initialization example uses your app's `getAccessToken` function to return a bearer token.

## Configure the global timeout

Add `timeout` to your client initialization code. All requests use this value unless you set a per-request timeout.

The following examples set the global timeout to 5,000 milliseconds (5 seconds):

::::tabs
:::tab{title="Client-side"}

The `client` package uses a default timeout of 30,000 milliseconds (30 seconds) if you don't set `timeout`.

```typescript
import { ClientSDK } from "@sitecore-marketplace-sdk/client";
import { XMC } from "@sitecore-marketplace-sdk/xmc";

const client = await ClientSDK.init({
  target: window.parent,
  modules: [XMC],
  timeout: 5000,
});
```

:::
:::tab{title="Server-side"}

Set `timeout` in the experimental client configuration:

```typescript
import { experimental_createXMCClient } from "@sitecore-marketplace-sdk/xmc";

const xmc = await experimental_createXMCClient({
  getAccessToken,
  timeout: 5000,
});
```

:::
::::

## Configure a per-request timeout

Add `timeoutMs` to the request options, not to `params`. The following examples use a timeout of 40,000 milliseconds (40 seconds) for that request only.

Replace `<YOUR_CONTEXT_ID>` with the Context ID of your SitecoreAI environment, which you can retrieve from the [application context](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/query-the-application-context.html "Query the application context").

::::tabs
:::tab{title="Client-side"}

For a query, set `timeoutMs` in the query options and check the returned `error`:

```typescript
const { data, error } = await client.query("xmc.sites.listSites", {
  timeoutMs: 40000,
  params: {
    query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
  },
});

if (error) {
  console.error("Error listing sites:", error);
} else {
  console.log("Sites:", data?.data);
}
```

For a mutation, set `timeoutMs` in the mutation options and handle errors using `catch`:

```typescript
try {
  const response = await client.mutate("xmc.authoring.graphql", {
    timeoutMs: 40000,
    params: {
      query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
      body: { query: "query { sites { name } }" },
    },
  });
  console.log("GraphQL response:", response);
} catch (error) {
  console.error("Error making GraphQL query:", error);
}
```

:::
:::tab{title="Server-side"}

Set `timeoutMs` in the experimental method's options:

```typescript
try {
  const { data, error } = await xmc.sites.listSites({
    query: { sitecoreContextId: "<YOUR_CONTEXT_ID>" },
    timeoutMs: 40000,
  });
  if (error) {
    console.error("Error listing sites:", error);
  } else {
    console.log("Sites:", data);
  }
} catch (error) {
  console.error("Error making Sites API request:", error);
}
```

:::
::::

## Handle timeout errors

For client-side queries, check the returned `error` or use the `onError` callback. Mutations reject when a request times out, so use `catch` to handle the error.

A timeout doesn't confirm that the operation was canceled. Check whether a mutation succeeded before retrying it.

For more information, see [Troubleshooting the Marketplace SDK](https://doc.sitecore.com/mp/en/developers/sdk/0/sitecore-marketplace-sdk/troubleshooting-the-marketplace-sdk.html#request-times-out "Request times out").
