---
title: "Timeout Plugin"
description: "Automatically abort requests that exceed a timeout with an AbortError, using a static value or a per-request dynamic timeout."
sidebar:
  label: "Timeout"
---

## Usage

```ts
import { TimeoutLinkPlugin } from '@orpc/client/plugins'

const link = new RPCLink({
  plugins: [
    new TimeoutLinkPlugin({
      timeout: 10_000, // 10 seconds
    }),
  ],
})
```

:::info
The `link` can be any supported oRPC link, such as [RPCLink](/docs/rpc/link), [OpenAPILink](/docs/openapi/link), or a custom one.
:::

## Dynamic Timeout

The `timeout` option also accepts a function, so you can resolve the timeout per request from the interceptor options, such as the procedure `path` or the [client context](/docs/client/client-side#client-context):

```ts
const link = new RPCLink({
  plugins: [
    new TimeoutLinkPlugin({
      timeout: ({ context, path }) => context.timeout ?? 10_000,
    }),
  ],
})
```

:::info
Return `null` or `undefined` to disable the timeout, which is useful for excluding long-lived requests. Any number always enables the timeout.
:::

## Learn More

For implementation details, see the [source code](https://github.com/middleapi/orpc/blob/main/packages/client/src/plugins/timeout.ts).
