# RateLimiter

`class` in `services` · v0.8.2

<https://docs.seedcord.org/packages/services/0.8.2/classes/rate-limiter>

Tracks per-key usage windows and reports when a key is limited and when it frees up.

Each key holds a sliding window of hit expiry times, and is limited once its live-hit count reaches the window's `limit`. Expired hits are dropped on the next read, and a background sweep drops fully-expired keys so the map does not grow without bound.

```ts
class RateLimiter
```

## Constructors

### constructor

```ts
RateLimiter()
```

Constructs a new instance of the `RateLimiter` class

## Properties

### size

```ts
public get size(): number
```

Number of keys currently tracked.

## Methods

### hit

```ts
public hit(
    key: string,
    window: RateLimitWindow
): RateLimitResult
```

Records a hit for `key` and reports whether the key is now limited.

### peek

```ts
public peek(
    key: string,
    window: RateLimitWindow
): RateLimitResult
```

Reports whether `key` is limited right now without recording a hit.

The read half of a peek-then-commit. A gate calls `peek` to decide whether to refuse, and `hit` to charge the slot only once it is the gate that let the request through.
