In short
- Limit the endpoints that spend or protect first: login, sign-up, password reset, email and SMS senders, AI routes. Public read endpoints can wait.
- Supabase Auth has built-in limits, for example 30 requests per 5 minutes per IP on sign-up and recovery by default. Your own API routes have none until you add them.
- Vercel's firewall allows one rate limiting rule per project on the Hobby plan. Cloudflare's Free plan also includes one rule, counted by IP.
- Limit AI routes per signed-in user and per day, and require a session first. An IP limit alone does not stop a patient script.
- Test gently: about a dozen wrong logins against your own endpoint is enough to see whether a 429 ever comes back.
On this page
What rate limiting an API means
Rate limiting is a counter in front of an endpoint. Each request from the same source, such as an IP address, a user or an API key, adds one. When the count passes a threshold inside a time window, the next requests are refused, usually with the HTTP status 429 Too Many Requests and often a Retry-After header that says when to try again.
Without it, every endpoint you expose accepts as many calls as a script can send. For most routes that is only a performance question. For a few, each call guesses a password, sends an email you pay for, or spends tokens on a model. Those are the ones to deal with first.
Which endpoints need a limit first
| Endpoint | What unlimited calls allow | Count by |
|---|---|---|
| Login | Trying leaked passwords against many accounts, one request each | IP and account |
| Sign-up | Thousands of throwaway accounts that use your credits or your storage | IP |
| Password reset and magic link | A mailbox flooded with reset emails in your name, and your email quota spent | Target address and IP |
| Anything that sends email or SMS | A bill per message. SMS is the expensive one | User, target and IP |
| Anything that calls a paid model | Your OpenAI or Anthropic budget spent by someone else | User, with a daily cap |
| Expensive searches and exports | A slow database for everyone | User or IP |
The last row can wait. The first five are worth an afternoon before a launch. AI routes are a special case, because the real fix is a session check before any limit. The guide on unprotected AI endpoints covers that route by route.
Supabase Auth: what is already limited
If your sign-in goes through Supabase Auth, the auth endpoints come with limits. Supabase documents these defaults:
| Operation | Default limit | Counted by |
|---|---|---|
| Emails sent with the built-in provider | 2 per hour | Project |
| Sign-up, recovery, resend, magic link and OTP endpoints | 30 requests per 5 minutes | IP address |
| A new OTP, magic link, confirmation or reset for the same user | One per 60 seconds | User |
| Token endpoint: password sign-in and refresh | 150 requests per 5 minutes | IP address |
| SMS messages | 30 per hour | Project |
| Anonymous sign-ins | 30 per hour | IP address |
You change them in the dashboard under Authentication, then Rate Limits. Two points matter for a maker. The limit of 2 emails an hour applies to the built-in mail provider, which is meant for testing: with your own SMTP provider the number is yours to set, so set it. And these limits cover /auth/v1/ only. A table read through the REST API, an RPC or an Edge Function has no such counter by default. The Supabase Auth guide covers the other auth settings.
At the edge: Vercel and Cloudflare
A rule at the hosting layer counts requests before they reach your code. It needs no deploy, and it protects routes the coding agent wrote without thinking about abuse.
- 1
Vercel
Rate limiting is part of the Vercel firewall and available on all plans. Open your project, then Firewall, Configure, New Rule, add a condition such as the request path, and choose Rate Limit as the action. The defaults are 100 requests per 60 seconds, counted by IP, with a 429 answer. The Hobby plan allows one rate limiting rule per project, with a window between 10 seconds and 10 minutes.
- 2
Cloudflare
In the dashboard, open Security rules, then Create rule and Rate limiting rules. Pick the path, the number of requests, the period and the action. The Free plan includes one rule, counted by IP.
- 3
Spend the one rule well
With a single rule, cover the paths that send or spend: for example every path that starts with
/api/author/api/chat. A tight number on a few paths is better than a loose number on the whole site.
Two limits of edge rules are worth knowing. Vercel notes that counters are tracked per region, so traffic spread over several regions can pass the number you set. And both free tiers count by IP, which treats an office behind one address as one visitor and a script with many addresses as many.
In your code: a per-user limit
For anything behind a login, count by user. Serverless functions do not share memory, so the counter has to live in a store. Upstash's @upstash/ratelimit library is a common choice because it talks to Redis over HTTP and runs on Vercel, Cloudflare Workers and Next.js. The pattern below is from its documentation, adapted to a route.
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
// 10 requests per 10 seconds for each identifier
const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(10, "10 s"),
});
export async function POST(req: Request) {
const user = await getUser(req); // your own session check
if (!user) return new Response("Unauthorized", { status: 401 });
const { success } = await ratelimit.limit(user.id);
if (!success) return new Response("Too many requests", { status: 429 });
// the expensive work goes here
}Redis.fromEnv() reads UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN. getUser stands for your own auth.The session check comes before the counter. For an AI route, add a second limiter with a daily window, so a single account cannot spend more than you decided in a day. For a login route there is no user yet: count by IP and by the email being tried, and keep the answer identical whether the account exists or not.
How to test your own rate limit, gently
You do not need a load test to know whether a limit exists. Send a dozen wrong logins to your own endpoint, with an address that belongs to nobody, and watch the status codes. Run it against your own app only.
# Your own app only. 12 wrong logins, one per second.
for i in $(seq 1 12); do
curl -s -o /dev/null -w "%{http_code}\n" \
-X POST "https://YOUR-APP.com/api/auth/login" \
-H "content-type: application/json" \
-d '{"email":"[email protected]","password":"wrong"}'
sleep 1
done- The login route answers 429, or shows a challenge, at some point in a short series of wrong attempts
- The password reset route refuses a second request for the same address within a minute
- Sign-up asks for an email confirmation or a challenge before the account can use paid features
- Every AI route returns 401 without a session, before any model is called
- Each signed-in user has a daily cap on AI calls
- Your email and SMS providers have a spending cap or an alert set in their own dashboards
Twelve requests prove little about a high limit. If your rule allows 100 a minute, this test will not reach it, and that is fine: read the rule in the dashboard instead of hammering your own site.
The traps after the first rule is in
- The limit trusts a header. If your code reads the visitor's IP from
X-Forwarded-Forwithout knowing which proxy set it, a script can send a new value on each request and never be counted twice. - Only the page is limited. The rule covers
/login, the page, while the form posts to/api/auth/login, which has no rule. - The old route still works. A
/api/v1/path the app no longer uses is still deployed, without the limiter added to/api/v2/. - The limit is per instance. A counter kept in memory resets on every cold start and is not shared between serverless instances.
- Sign-up is free and instant. A per-user cap on AI calls means little if a script can create a new user every second.
What Keybrum tests about rate limits
Keybrum is the automated pentest we build for apps made with AI. On rate limits it tests a narrow, safe slice, on your live app, and says so in the report.
- Sign-in throttling. When your own backend exposes a sign-in route, it sends eight invalid sign-ins for a random address that belongs to no real account. It stops at the first 429,
Retry-Afterheader or human-verification answer. If all eight reach password validation, it reports a low-severity finding, and states that eight requests do not prove unlimited throughput. - Instant accounts. It records whether the test account it creates was accepted at once, with no CAPTCHA, no throttling and no email confirmation.
- AI routes without a session. It sends three short prompts to routes and Supabase Edge Functions that look like AI endpoints, to see whether a model answers a stranger.
- Account enumeration. It compares the answers of sign-in, register and reset routes for its own test account and for a random address, since different answers tell a script which emails are registered.
What it does not do: it never floods an endpoint, never runs denial-of-service traffic, and does not measure the exact threshold of your rule. It does not send reset emails or SMS in a loop, so the limits on those senders are yours to check with the list above. It only attacks apps whose owner proved ownership.
A one-time report costs €49. The Maker plan, €29 a month excluding VAT for 5 apps, runs the attacks again on every deploy, which is when a new unprotected route tends to appear.
Questions
What is API rate limiting?
It is a cap on how many requests one source can send to an endpoint in a time window. Requests over the cap are refused, usually with HTTP 429. It protects logins from password guessing and paid services from being spent by scripts.
Which endpoints should I rate limit first?
Login, sign-up, password reset, anything that sends an email or an SMS, and anything that calls a paid model. These either guard accounts or cost money per call. Read-only public endpoints can come later.
Does Supabase have rate limiting?
Supabase Auth does, on its /auth/v1/ endpoints, with defaults such as 30 requests per 5 minutes per IP on sign-up and recovery. You adjust them under Authentication, then Rate Limits. Table reads, RPCs and Edge Functions are not covered by those auth limits.
Is rate limiting on Vercel available on the Hobby plan?
Yes. Vercel's documentation says WAF rate limiting is available on all plans. The Hobby plan allows one rate limiting rule per project, with a fixed window between 10 seconds and 10 minutes, counted by IP or JA4 digest.
What status code should a rate limited request return?
429 Too Many Requests, ideally with a Retry-After header that tells the client how long to wait. Vercel's firewall uses 429 as its default action, and Supabase Auth returns 429 when a limit is passed.
Is rate limiting enough to protect an AI endpoint?
No. The route first needs a session check, so that only signed-in users reach the model. Then add a per-user limit and a daily cap, and set a spending limit with the model provider. The unprotected AI endpoint guide goes through each layer.
Sources
- 1.Rate limits, Supabase Docs
- 2.WAF Rate Limiting, Vercel Docs
- 3.Rate limiting rules, Cloudflare Docs
- 4.Create a rate limiting rule in the dashboard, Cloudflare Docs
- 5.Ratelimit: getting started, Upstash Docs