---
title: EdgeRateLimiter
summary: Provides Edge Rate Limiting by combining a RateCounter and a PenaltyBox.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/class.EdgeRateLimiter/
---

**Kind:** Class  
**Module:** [edge-rate-limiter](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/)  
**Package:** @fastly/js-compute 4.0.1  
**Since:** 3.9.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/edge-rate-limiter.d.ts#L10

Provides [Edge Rate Limiting](https://docs.fastly.com/products/edge-rate-limiting) by
combining a [RateCounter](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/class.RateCounter/) and a [PenaltyBox](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/class.PenaltyBox/).

**Note**: Can only be used when processing requests, not during build-time initialization.

## Constructor

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/edge-rate-limiter.d.ts#L19

```javascript
new EdgeRateLimiter(rateCounter: RateCounter, penaltyBox: PenaltyBox)
```

Open an EdgeRateLimiter with the given rate counter and penalty box.

**Parameters**

- `rateCounter`: `RateCounter` — The RateCounter instance to associate with this EdgeRateLimiter.
- `penaltyBox`: `PenaltyBox` — The PenaltyBox instance to associate with this EdgeRateLimiter.

**Throws**

- `TypeError` If `rateCounter` is not an instance of RateCounter.
or if `penaltyBox` is not an instance of PenaltyBox.

## Methods

### checkRate

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/edge-rate-limiter.d.ts#L38

```javascript
checkRate(entry: string, delta: number, window: 1 | 10 | 60, limit: number, timeToLive: number): boolean
```

Increment an entry in the rate counter and check if the entry has exceeded
some average number of requests per second (RPS) over the given window.
If the entry is over the RPS limit for the window, add it to the penalty
box for the given `timeToLive`.

**Parameters**

- `entry`: `string` — The name of the entry to increment and check.
- `delta`: `number` — The amount to increment the entry by.
- `window`: `1 | 10 | 60` — The time period in seconds to check across.
- `limit`: `number` — The requests-per-second limit.
- `timeToLive`: `number`

  How long in minutes (1–60) the entry should be added
    into the penalty box. Value is truncated to the nearest minute.

**Returns**

`boolean`

`true` if the entry has exceeded the average RPS for the window,
  otherwise `false`.

**Throws**

- `TypeError` If `delta` is not a non-negative finite number,
if `window` is not 1, 10, or 60, if `limit` is not a non-negative finite number,
or if `timeToLive` is not a number between 1 and 60.
