Watch: Stop people spamming my API with rate limits | Vovy

Watch Vovy do it on a Mac: "Add a rate limit so each user can only hit my AI endpoint 10 times a minute". Create an Upstash Redis database and use @upstash/ratelimit to cap requests per user or IP, so bots can't run up your bill.

"Add a rate limit so each user can only hit my AI endpoint 10 times a minute"

Create an Upstash Redis database and use @upstash/ratelimit to cap requests per user or IP, so bots can't run up your bill.

What happens in the video

  1. Create an Upstash Redis database: Redis is a very fast store for small counters. Vovy creates a database in the Upstash console in a region close to your host.
  2. Copy the REST URL and token: Vovy copies UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN into your .env and Vercel's environment variables.
  3. Add the rate limiter: Vovy installs @upstash/ratelimit and adds a check to your endpoint, like 10 requests per minute per signed-in user or IP address.
  4. Return a friendly error: When someone hits the limit, your API returns status 429 Too Many Requests and your app shows a clear message instead of breaking.
  5. Test the limit: Vovy fires requests past the limit and shows a card: which ones passed, which got 429, and when the counter resets.
Read the step-by-step guide