Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/get-convex/rate-limiter/llms.txt

Use this file to discover all available pages before exploring further.

The Convex Rate Limiter exports helpful time constants to make rate limit configurations more readable.

Time Constants

All time constants are in milliseconds.

SECOND

export const SECOND = 1000;
Represents one second (1,000 milliseconds). Example:
import { SECOND } from "@convex-dev/rate-limiter";

const config = {
  kind: "token bucket",
  rate: 5,
  period: SECOND // 1000ms
};

MINUTE

export const MINUTE = 60 * SECOND;
Represents one minute (60,000 milliseconds). Value: 60000 Example:
import { MINUTE } from "@convex-dev/rate-limiter";

const config = {
  kind: "token bucket",
  rate: 10,
  period: MINUTE // 60000ms
};

HOUR

export const HOUR = 60 * MINUTE;
Represents one hour (3,600,000 milliseconds). Value: 3600000 Example:
import { HOUR } from "@convex-dev/rate-limiter";

const config = {
  kind: "fixed window",
  rate: 100,
  period: HOUR // 3600000ms
};

DAY

export const DAY = 24 * HOUR;
Represents one day (86,400,000 milliseconds). Value: 86400000 Example:
import { DAY } from "@convex-dev/rate-limiter";

const config = {
  kind: "fixed window",
  rate: 1000,
  period: DAY // 86400000ms
};

WEEK

export const WEEK = 7 * DAY;
Represents one week (604,800,000 milliseconds). Value: 604800000 Example:
import { WEEK } from "@convex-dev/rate-limiter";

const config = {
  kind: "fixed window",
  rate: 10000,
  period: WEEK // 604800000ms
};

Usage in Rate Limits

These constants make rate limit configurations more readable and maintainable:
import { RateLimiter, SECOND, MINUTE, HOUR, DAY } from "@convex-dev/rate-limiter";
import { components } from "./_generated/api";

const rateLimiter = new RateLimiter(components.rateLimiter, {
  // 10 requests per second
  apiCalls: {
    kind: "token bucket",
    rate: 10,
    period: SECOND
  },
  // 100 messages per minute
  sendMessage: {
    kind: "token bucket",
    rate: 100,
    period: MINUTE,
    capacity: 20
  },
  // 1000 requests per hour
  apiHourly: {
    kind: "fixed window",
    rate: 1000,
    period: HOUR
  },
  // 10000 requests per day
  dailyQuota: {
    kind: "fixed window",
    rate: 10000,
    period: DAY
  }
});

Combining Constants

You can combine or multiply constants for custom periods:
import { MINUTE, HOUR } from "@convex-dev/rate-limiter";

// 30 minutes
const thirtyMinutes = 30 * MINUTE;

// 6 hours
const sixHours = 6 * HOUR;

// 90 seconds
const ninetySeconds = 90 * SECOND;

const config = {
  kind: "token bucket",
  rate: 50,
  period: thirtyMinutes
};
All time constants are in milliseconds to match JavaScript’s Date.now() and Convex’s time units.