StoicBuilder

HandbookIII the CastraRate limits

IIIthe Castra, Stay in control

Rate limits

1 min readUpdated 28 November

In plain words

A rate limit caps how many requests one user or IP address can make per minute, so a single caller can't flood your app or run up your bills.

Where you see it

Quill has a "Summarise this note" button that calls OpenAI. Someone scripts it to run 50,000 times overnight, and the bill arrives before you notice. Signup forms that send email through Resend get abused the same way.

app/api/summarise/route.tsserver
import { Ratelimit } from "@upstash/ratelimit";import { Redis } from "@upstash/redis";const limiter = new Ratelimit({ redis: Redis.fromEnv(), limiter: Ratelimit.slidingWindow(10, "1 m"),});const { success } = await limiter.limit(user.id);if (!success) return new Response("Slow down", { status: 429 });
Ten calls a minute per user. The eleventh gets a 429.

What goes wrong

  1. No limit on routes that cost money

    AI calls, text messages and emails are billed per request. Without a cap, one script can spend a month's budget overnight.

  2. Limiting only in the browser

    Disabling the button for ten seconds stops honest double-clicks, not a script that calls your API directly.

  3. Counting in memory on serverless hosting

    On Vercel, requests can land on different short-lived instances, so a counter kept in a variable keeps resetting. Store counts somewhere shared, like Redis.

    const hits = new Map(); // empty again on every new instance

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Add rate limits to login, signup, password reset and every route that calls a paid API, keyed by user ID or IP address and stored somewhere shared like Upstash Redis. Return a 429 when the limit is hit, and tell me which provider dashboards need a monthly spending cap.

Quick check

Sign in to earn +10 XP for it

Your rate limit lives in a variable inside a Vercel function and doesn't seem to work. Why?

Got a prompt that touches rate limits?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.