Protecting your API routes from abuse.
rate-limit
package powered by @upstash/ratelimit
, a connectionless (HTTP-based) rate limiting library designed specifically for serverless and edge environments.
web
package contact form automatically by the existence of a UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
environment variable. If enabled, the contact form will limit the number of requests to 1 per day per IP address.
To get your environment variables, you can sign up at Upstash Console and create a Redis KV database. You can then find the REST URL and REST token in the database details page.
You can then paste these environment variables each of the environment variables files.
createRateLimiter
function. For example, to limit the number of AI requests to 10 per 10 seconds per IP address, you can do something like this:
rate-limit
package connects to an Upstash Redis database and automatically limits the number of requests to your API routes.
The default rate limiting configuration allows 10 requests per 10 seconds per identifier. @upstash/ratelimit
also has other rate limiting algorithms such as:
rate-limit
package. For example:
analytics
configuration to rate limit client:
Choose Appropriate Identifiers
Configure Rate Limits
Implement Error Handling
Monitor and Adjust
@upstash/ratelimit
also provides several advanced features: