lymitdocs

docs

Getting started

Install the SDK, declare a namespace, make your first limit check.

Lymit is application-level rate limiting: you limit by the identifiers your app already has — userId, workspaceId, tier:pro — and, for AI features, by the cost of each request in tokens rather than by request count.

1. Install

1npm install @lymit/sdk

Zero dependencies. Runs on Node 18+, Bun, Deno and Cloudflare Workers.

2. Get a key

Sign in with GitHub. A workspace and a live API key are created immediately; the quickstart page shows the key once. Put it in your environment as LYMIT_API_KEY.

3. Declare a namespace and check a limit

1import { Lymit } from "@lymit/sdk";23const lymit = new Lymit({ apiKey: process.env.LYMIT_API_KEY });45const ai = lymit.namespace("ai_generation", {6  algorithm: "tokenBucket",7  capacity: 5000, // tokens the bucket holds8  refillRate: 1000, // tokens added every `interval`9  interval: "1h",10});1112const { success, remaining, reset, retryAfter } = await ai.limit(user.id, {13  cost: estimatedTokens,14});15if (!success) return new Response("Budget exhausted", { status: 429 });

A rejection is a normal result (success: false), never an exception. The first request lights up the radar on your quickstart page and your dashboard fills in.

What happens on each call

Your app makes one HTTPS request to the Lymit edge. The edge authenticates the key, layers any dashboard overrides over the config you declared, and asks the counter for that namespace — a single-threaded object holding the state for every identifier — whether the cost fits. The decision is recorded for your dashboard after the response is sent, so telemetry never slows a request.