Skip to main content

Overview

The check() method checks a rate limit’s current status without consuming any tokens. This is useful for previewing whether a request would be allowed, or for checking rate limits in queries where you cannot consume tokens.

Method Signature

Key Difference from limit()

Unlike limit(), the check() method:
  • Does not consume tokens - It only reads the current state
  • Can be used in queries - Since it doesn’t mutate state, it works with runQuery
  • Returns the same shape - The return type is identical to limit()
This makes check() perfect for UI indicators, permission checks, or deciding whether to attempt an operation.

Parameters

RunQueryCtx
required
The context object from a query or mutation, including runQuery. Unlike limit(), this works with query contexts.
string
required
The name of the rate limit to check. If this name was defined in the RateLimiter constructor, it will be type-checked and auto-completed.
object
Optional configuration for this rate limit check.
string
A unique identifier for this rate limit instance. Use this to check per-user, per-IP, or other scoped rate limits.
number
default:"1"
The number of tokens to check for availability. The check will return whether this many tokens are available without consuming them.
boolean
default:"false"
If true, checks whether tokens can be reserved for future use. Returns retryAfter indicating when the reserved work should execute.
RateLimitConfig
The rate limit configuration. Required only if the rate limit name was not defined in the RateLimiter constructor.
The throws option is not available for check() since it’s typically used for non-blocking status checks.

Return Type

object
Returns a promise that resolves to one of two shapes:When rate limit is not exceeded:
true
required
Indicates the request would be allowed.
number
Only present when reserve: true. The duration in milliseconds to wait before executing the reserved work.
When rate limit is exceeded:
false
required
Indicates the rate limit would be exceeded.
number
required
The duration in milliseconds when retrying could succeed.

Use Cases

Preview Before Action

Check if an action would be rate-limited before attempting it:

Query for UI Status

Use in a query to show rate limit status in your UI:

Batch Operations

Check if multiple operations would succeed before starting:

Cost Estimation

Check if a large operation would be allowed:

Notes

Since check() doesn’t consume tokens, calling it multiple times won’t affect the rate limit state. This makes it safe to use in queries and for UI status indicators.
When using check() followed by limit() in the same mutation, there’s a small time gap between the check and the actual consumption. The rate limit state could change between these calls. Use check() for guidance, not as a guarantee.
Always call limit() to actually enforce the rate limit. Using only check() without limit() will not consume tokens and won’t prevent rate limit violations.