---
title: RateCounter
summary: A rate counter that can be used with EdgeRateLimiter or standalone for counting and rate calculations.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/class.RateCounter/
---

**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#L88

A rate counter that can be used with [EdgeRateLimiter](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/edge-rate-limiter/class.EdgeRateLimiter/) or standalone
for counting and rate calculations.

**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#L94

```javascript
new RateCounter(name: string)
```

Open a RateCounter instance with the given name.

**Parameters**

- `name`: `string` — The name of the rate counter.

## Methods

### increment

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

```javascript
increment(entry: string, delta: number): void
```

Increment the given entry by `delta`.

**Parameters**

- `entry`: `string` — The entry to increment.
- `delta`: `number` — The amount to increment the entry by.

**Returns**

`void`

**Throws**

- `TypeError` if `delta` is not a non-negative finite number.

### lookupCount

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

```javascript
lookupCount(entry: string, duration: 10 | 20 | 30 | 40 | 50 | 60): number
```

Look up the current count for an entry over a given duration.

**Parameters**

- `entry`: `string` — The entry to look up.
- `duration`: `10 | 20 | 30 | 40 | 50 | 60` — The duration in seconds to look up alongside the entry.

**Returns**

`number`

The count for the given entry and duration.

**Throws**

- `TypeError` if `duration` is not 10, 20, 30, 40, 50, or 60.

### lookupRate

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

```javascript
lookupRate(entry: string, window: 1 | 10 | 60): number
```

Look up the current rate for an entry over a given window.

**Parameters**

- `entry`: `string` — The entry to look up.
- `window`: `1 | 10 | 60` — The time window in seconds to look up alongside the entry.

**Returns**

`number`

The rate for the given entry and window.

**Throws**

- `TypeError` if `window` is not 1, 10, or 60.
