Skip to main content
This page documents all exported TypeScript types for the Convex Rate Limiter.

RateLimitConfig

A union type representing the configuration for a rate limit. Can be either a token bucket or fixed window configuration.

Token Bucket Configuration

A token bucket limits the rate of requests by continuously adding tokens to be consumed when servicing requests.
Example:

Fixed Window Configuration

A fixed window rate limit adds a set number of tokens at the start of each fixed window of time.
Example:

RateLimitArgs

Arguments for rate limiting operations.
Example:

RateLimitReturns

Return value from rate limiting operations.
Example:

RateLimitError

Error type thrown when throws: true is used and the rate limit is exceeded.
literal
required
Always "RateLimited" to identify this error type
string
required
The name of the rate limit that was exceeded
number
required
Duration in milliseconds when retrying could succeed
Example:

GetValueArgs

Arguments for getting the current value of a rate limit.
string
The name of the rate limit
string
The key to check. If not provided, checks the shared value.
number
The number of shards to sample when checking the value
RateLimitConfig
The rate limit configuration if not using a pre-defined limit
Example:

GetValueReturns

Return value from getting the current rate limit value.
number
required
The current number of available tokens
number
required
The timestamp of the last update (in milliseconds)
number
required
The shard number that was sampled
RateLimitConfig
required
The rate limit configuration
Example:

Validators

Convex validators for rate limit configurations.

tokenBucketValidator

Convex validator for token bucket configurations. Use with Infer<typeof tokenBucketValidator> to get the TypeScript type.

fixedWindowValidator

Convex validator for fixed window configurations. Use with Infer<typeof fixedWindowValidator> to get the TypeScript type.

Context Types

Context types used by the RateLimiter methods to specify which Convex operations are available.

RunQueryCtx

A context that provides access to runQuery. Used by non-mutating operations like check() and getValue().
Example:

RunMutationCtx

A context that extends RunQueryCtx and provides access to both runQuery and runMutation. Used by mutating operations like limit() and reset().
Example:
These types are satisfied by the standard Convex QueryCtx and MutationCtx types, so you typically don’t need to reference them directly. They’re used internally to ensure type safety.