> ## Documentation Index
> Fetch the complete documentation index at: https://docs.limitem.com/llms.txt
> Use this file to discover all available pages before exploring further.

# limit.em

> Create a limiter. Check an identifier.

## Constructor

```typescript theme={null}
import { limit } from "limitem";

const limiter = new limit.em({
  token: process.env.LIMITEM_TOKEN,
  namespace: "contiguity-api",
  product: "outbound_sms",
  limit: 100,
  duration: "1h",
  algorithm: "fixed-window",
  timeout: 800,
  fail_closed: false,
}, "https://api.limitem.com");
```

The second argument is the base URL. Leave it alone unless you're pointing at a non-production host.

### Options

<ParamField body="token" type="string">
  API token. Falls back to `LIMITEM_TOKEN` or `LIMITEM_KEY`.
</ParamField>

<ParamField body="namespace" type="string" required>
  Application namespace.
</ParamField>

<ParamField body="limit" type="number" required>
  Requests allowed in the window.
</ParamField>

<ParamField body="duration" type="string | number" required>
  Window size. A number is seconds. Strings: `"30s"`, `"5m"`, `"1h"`, `"1d"`.
</ParamField>

<ParamField body="product" type="string">
  Optional product. Becomes `namespace.product`.
</ParamField>

<ParamField body="algorithm" default="fixed-window" type="string">
  `fixed-window` | `sliding-window` | `token-bucket` | `leaky-bucket`.
</ParamField>

<ParamField body="timeout" default="800" type="number">
  Abort the Limitem request after this many milliseconds.
</ParamField>

<ParamField body="fail_closed" default="false" type="boolean">
  When `true`, outages return `allowed: false` instead of failing open.
</ParamField>

## limiter.limit(identifier)

Consume one request for `identifier`.

```typescript theme={null}
const result = await limiter.limit("user:123");
```

### Response

<ResponseField name="allowed" type="boolean">
  Whether this request is allowed.
</ResponseField>

<ResponseField name="success" type="boolean">
  Same as `allowed`. Kept for older Contiguity callers.
</ResponseField>

<ResponseField name="namespace" type="string">
  Effective namespace, including product if you set one.
</ResponseField>

<ResponseField name="limit" type="number">
  The limit you configured.
</ResponseField>

<ResponseField name="remaining" type="number">
  Requests left in the current window.
</ResponseField>

<ResponseField name="reset_time" type="number">
  Unix timestamp (seconds) when the window resets — meaning depends on the [algorithm](/algorithms/overview).
</ResponseField>

<ResponseField name="count" type="number">
  How many requests are in the window after this check.
</ResponseField>

<ResponseField name="algorithm" type="string">
  Algorithm used.
</ResponseField>

<ResponseField name="failover" type="boolean">
  Present when the SDK could not reach Limitem.
</ResponseField>

<ResponseField name="degraded" type="boolean">
  Present when the API failed open on its side.
</ResponseField>

<ResponseField name="retry_after" type="number">
  Seconds to wait. Only on a 429 from the API.
</ResponseField>

<ResponseField name="_request" type="object">
  `{ success, processing_time_ms }` from the API.
</ResponseField>
