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.Fixed Window Configuration
A fixed window rate limit adds a set number of tokens at the start of each fixed window of time.RateLimitArgs
Arguments for rate limiting operations.RateLimitReturns
Return value from rate limiting operations.RateLimitError
Error type thrown whenthrows: true is used and the rate limit is exceeded.
literal
required
Always
"RateLimited" to identify this error typestring
required
The name of the rate limit that was exceeded
number
required
Duration in milliseconds when retrying could succeed
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
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
Validators
Convex validators for rate limit configurations.tokenBucketValidator
Infer<typeof tokenBucketValidator> to get the TypeScript type.
fixedWindowValidator
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 torunQuery. Used by non-mutating operations like check() and getValue().
RunMutationCtx
A context that extendsRunQueryCtx and provides access to both runQuery and runMutation. Used by mutating operations like limit() and reset().
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.