Skip to main content

Overview

Sometimes you need to check if a rate limit would allow a request without actually consuming any tokens. The Convex Rate Limiter provides two methods for this:
  1. check() - Check if a request would be allowed
  2. getValue() - Get the current token count and metadata

The check() Method

The check() method evaluates a rate limit without consuming any tokens:
From src/client/index.ts:78-111:

Difference Between check() and limit()

Key differences:

Use Cases for Checking Without Consuming

1. Showing Rate Limit Status to Users

Display remaining capacity before the user takes action:
Then in your UI:

2. Validating Before Expensive Operations

Check capacity before starting expensive work:

3. Conditional Logic Based on Capacity

4. Real Example from Source Code

From example/convex/example.ts:80-85:

The getValue() Method

For more detailed information about the current state, use getValue():
From src/client/index.ts:168-209:

Return Value Structure

Example: Displaying Quota Information

Then display in your UI:

Using calculateRateLimit

You can calculate the value at a specific timestamp using the calculateRateLimit helper:
From the README:
“You can use calculateRateLimit to calculate the value at a given timestamp”

Check with Custom Count

You can check if there’s enough capacity for a specific count:

Best Practices

For operations that are expensive to start but cheap to validate:
Queries can’t consume tokens (they can’t modify state), so use check():
If you check in a query and then limit in a mutation, the state might change between calls. For critical operations, just use limit() directly:
Track rate limit utilization over time:

Next Steps