Configure convex.config.ts
Create or update
convex/convex.config.ts to register the component:convex/convex.config.ts
Define Your Rate Limits
Create a new file (e.g.,
convex/rateLimits.ts) and define your rate limits:convex/rateLimits.ts
Rate limit strategies:
- Token bucket: Tokens are added at a steady rate, allowing bursts up to
capacity - Fixed window: All tokens granted at once every
period, with optional rollover
Use in a Mutation - Global Rate Limit
Apply a global rate limit that applies to all users:
convex/users.ts
Use in a Mutation - Per-User Rate Limit
Apply a rate limit specific to each user using a
key:convex/messages.ts
What You’ve Learned
You now know how to:- Install and configure the Convex Rate Limiter component
- Define rate limits with different strategies (token bucket and fixed window)
- Apply global rate limits that affect all users
- Apply per-user rate limits using keys
- Handle rate limit errors gracefully
- Reset rate limits when needed
Next Steps
Explore more advanced features:- Custom token counts: Consume multiple tokens in a single request for LLM token limiting
- Sharding: Scale to high throughput with configurable sharding
- Reservations: Reserve capacity to avoid starvation on larger requests
- React hook: Check rate limits from your frontend with
useRateLimit