> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Rate Limit

## Overview

The [`rateLimit`](/docs/transports/rate-limit) transport limits an inner
[Transport](/docs/transports) to `requestsPerSecond` requests each second.

Requests beyond the budget enter a first-in, first-out queue. The Transport sends queued requests as
the budget refreshes.

```ts twoslash
import { http, rateLimit } from 'viem'

const transport = rateLimit(http('https://eth.merkle.io'), {
  requestsPerSecond: 50,
})
```

## Recipes

### Throttling a Provider

```ts twoslash
import { http, rateLimit } from 'viem'

const transport = rateLimit(http('https://eth.merkle.io'), {
  requestsPerSecond: 50, // [!code focus]
})
```

### Restricting RPC Methods

Limit rate limiting to specific RPC methods when only some calls should share the same request budget.

```ts twoslash
import { http, rateLimit } from 'viem'

const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  methods: { include: ['eth_call'] }, // [!code focus]
})
```

### Configuring Retries

Tune retry behavior when the rate-limited transport needs a different retry budget or backoff delay.

```ts twoslash
import { http, rateLimit } from 'viem'

const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  retryCount: 5, // [!code focus]
  retryDelay: 200, // [!code focus]
})
```

## `rateLimit`

Creates a transport that throttles an inner transport to a fixed requests-per-second budget.

### Usage

```ts twoslash
import { http, rateLimit } from 'viem'

const transport = rateLimit(http('https://eth.merkle.io'), {
  requestsPerSecond: 50,
})
```

### Parameters

#### transport

* **Type:** `Transport`

The inner transport to throttle.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), { requestsPerSecond: 50 }) // [!code focus]
```

#### options.key

* **Type:** `string`
* **Default:** `'rateLimit'`

Transport key.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  key: 'rateLimit', // [!code focus]
})
```

#### options.methods

* **Type:** `{ include?: string[] } | { exclude?: string[] }`

RPC methods to include or exclude.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  methods: { include: ['eth_call'] }, // [!code focus]
})
```

#### options.name

* **Type:** `string`
* **Default:** `'Rate Limit'`

Transport name.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  name: 'Rate Limit', // [!code focus]
})
```

#### options.requestsPerSecond

* **Type:** `number`

Max number of requests per second.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50, // [!code focus]
})
```

#### options.retryCount

* **Type:** `number`
* **Default:** `3`

Max retries per request.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  retryCount: 5, // [!code focus]
})
```

#### options.retryDelay

* **Type:** `number`
* **Default:** `150`

Base delay (ms) between retries.

```ts twoslash
import { http, rateLimit } from 'viem'
// ---cut---
const transport = rateLimit(http(), {
  requestsPerSecond: 50,
  retryDelay: 200, // [!code focus]
})
```

### Return Value

`Transport<'rateLimit'>`

A rate-limited transport that queues requests beyond the budget.
