OWASP API security rate limiting means capping how much of your API any one caller can consume, as part of API4:2023 Unrestricted Resource Consumption. Limit per user or API key, not just per IP, tighten limits on login and expensive endpoints, cap page and body sizes, and return 429 Too Many Requests with a Retry-After header when a limit is hit.
Key takeaways
- Rate limiting is OWASP API4:2023 — without limits, one client can take your API down or run up your bill.
- Limit per authenticated user or API key, with stricter limits on login, password reset and expensive operations.
- Return 429 with Retry-After, and cap page sizes, body sizes and execution time as well as request counts.
An API with no limits is an open invitation. One script can send a million requests, ask for a million rows at a time, or trigger a paid service on every call — and your bill or your uptime pays for it.
What is OWASP API4: Unrestricted Resource Consumption?
API4:2023, Unrestricted Resource Consumption, is OWASP's category for APIs that fail to limit what a client can consume. It is the fourth item in the OWASP API Security Top 10 (2023 edition).
OWASP describes the risk plainly: many APIs do not limit client interactions or resource consumption, so an attacker can generate a high volume of requests, which can increase operational costs and lead to a denial of service. The risk is rated as widespread, easy to detect and severe in technical impact.
The category covers more than request counts. An API is vulnerable if any of these limits is missing: execution timeouts, memory and file limits, maximum upload size, maximum page size, or limits on operations per request, such as GraphQL batching. A single expensive request can do as much damage as a thousand cheap ones.
Why does rate limiting matter for API security?
Rate limiting protects three things at once: availability, cost and security. Without it, a flood of requests can exhaust your workers, your database connections or your bandwidth, and take the API down for everyone.
Cost is the risk teams most often miss. Some API operations trigger a paid service on your side, such as an SMS message, an email or a third-party lookup. OWASP gives the example of an SMS reset flow: a script that triggers thousands of messages can cost thousands of dollars in minutes.
Rate limiting also slows down attacks. Credential stuffing, password guessing, scraping and enumeration all depend on making many requests quickly. A tight limit on login and password-reset endpoints makes those attacks far slower and far noisier, which gives your monitoring a chance to catch them.
How does API rate limiting work?
Rate limiting counts requests from a caller over a window of time and rejects the excess. A common shape is a quota such as 100 requests per minute per API key, with a burst allowance for short spikes.
Two algorithms dominate. A fixed window counts requests in a clock-aligned period, such as each minute, and resets at the boundary. A token bucket gives each caller a bucket of tokens that refills steadily: each request spends a token, and requests with no token left are rejected.
Token buckets handle bursts more smoothly, while sliding windows avoid the boundary problem where a caller can send a full quota at the end of one window and another at the start of the next.
Where you enforce the limit matters too. Enforcing at the gateway or edge protects your services from ever seeing the flood, while enforcing in the application lets you set different limits per endpoint and per user. Most teams do both: a coarse limit at the edge and a fine-grained limit in the service.
What should you limit in an API?
Limit more than request counts. OWASP's API4 guidance covers every resource a request can consume, and a limit on counts alone leaves the expensive paths open.
| Limit | Why it matters | Example |
|---|---|---|
| Requests per caller | Stops floods and scraping | 100 per minute per API key |
| Login attempts | Slows credential stuffing | 5 per 15 minutes per account |
| Page size | Stops one request asking for a million rows | Maximum 100 items per page |
| Request body size | Blocks oversized payloads | Reject bodies over 1 MB with 413 |
| Upload size | Stops storage and processing abuse | Maximum file size per endpoint |
| Execution time | Stops slow requests tying up workers | Timeout per request |
| Operations per request | Closes GraphQL batching bypasses | Depth and cost limits on queries |
| Costly actions | Stops bill shock from paid services | Per-day cap on SMS or email triggers |
The examples above are illustrations, not recommended numbers. No standard publishes a correct requests-per-minute figure, because the right number depends on what your legitimate clients do. Measure first, then set limits.
Pay special attention to sensitive business flows, which OWASP covers separately as API6. Signup, checkout, booking and coupon redemption can be abused by automation even when each request is small, so they need velocity checks and per-account limits of their own.
Should you limit by IP, user or API key?
Limit by the authenticated user or API key first, and use IP address as a second layer. Identity is the fairest and most accurate key: it follows the real caller, and it cannot be dodged by switching networks.
IP-only limits have two problems. Many users share one IP behind an office network, a school or a mobile carrier, so one heavy user can lock out everyone behind the same address. And one attacker can use many IPs, through proxies or a botnet, so an IP limit barely slows them down.
Use several dimensions at once: per user, per API key, per IP, and per endpoint. Tighten the limits on sensitive endpoints — login, password reset, one-time code validation and expensive operations — and keep general limits looser. For login specifically, tie the failed-attempt counter to the account, so an attacker cannot reset it by rotating IPs.
What should you return when a limit is hit?
Return HTTP 429 Too Many Requests, defined in RFC 6585, with a Retry-After header telling the client how long to wait. That is the standard signal, and well-behaved clients and libraries understand it.
Include the limit in your response headers where you can, such as the remaining quota and the time it resets, so clients can back off before they hit the wall. Keep the error body short and consistent with your other errors, and do not reveal internal details.
Do not return 403, which suggests the caller is permanently denied, and do not silently drop requests. A silent drop looks like a bug to a legitimate client, and it teaches abusive clients nothing. A clear 429 with a Retry-After is both kinder and more effective.
Watch out for lockout as an attack in itself. If failed logins lock an account, an attacker can lock out your real users on purpose. Prefer short delays and per-account rate limits over hard lockouts, and give locked-out users a safe recovery path.
How do you set rate limits without breaking real users?
Start by measuring. Look at your real traffic for a week or two: requests per user per minute at peak, the busiest legitimate clients, and the patterns of bulk jobs and imports. Set your first limits above the highest normal use you see, not below it.
Roll limits out in stages. Begin in a monitoring mode that logs what would have been rejected, and review the log before you turn enforcement on. You will find the shared office IP, the bulk importer and the retry storm you forgot about — and you can allowlist or raise the quota for them first.
Give heavy legitimate users a path to a higher quota. A partner syncing data, a bulk importer or a busy integration should be able to request a larger limit, tied to their own API key, rather than hitting the same ceiling as an anonymous caller.
Document your limits. Publish them in your API docs, including the quota, the window, the 429 response and the Retry-After header, so developers can build retry logic that respects them.
What else does API4 need besides rate limits?
Rate limits are the headline fix, but API4 is about all resource consumption. Cap the size of request bodies and uploads, cap page sizes, set timeouts on slow operations, and limit query depth and cost for GraphQL. Each of these closes a bypass that request counts alone cannot.
Validate input against a schema before you process it, and reject requests that exceed your caps with a clear status such as 413 for an oversized body. Keep error messages generic, and log the detail on your side.
Protect the paths that cost you money. Put per-day caps on SMS, email and lookup triggers, and alert when any one caller approaches them. A cap that nobody watches is only a suggestion.
Our guide to how to ensure API security covers the full OWASP Top 10, including the authorization checks that rate limiting cannot replace. The OWASP API Security Project publishes the current list, and the OWASP Developer Guide explains each risk in more depth.
How do you test your rate limits?
Test in staging, with test accounts and test data. Send a burst of requests from one key and confirm you get 429 responses with Retry-After, not errors or silent drops. Ask for a huge page size and confirm it is capped. Send an oversized body and confirm it is rejected.
Test the sensitive endpoints separately. Try many wrong logins for a test account and confirm the limit bites. Try triggering a costly action repeatedly and confirm the per-day cap holds. Try the same attack from several IPs and confirm the per-account limit still applies.
Re-test after every major change. A new endpoint, a new version or a new integration can quietly bypass a limit that used to work, and the only way to catch it is to test again.
What are the common rate limiting mistakes?
The most common mistakes are easy to spot once you know them.
- IP-only limits. Shared IPs lock out innocent users, and attackers rotate IPs.
- One limit for everything. Login needs a far tighter limit than a read-only list endpoint.
- Counting requests but not cost. A single expensive request can do more damage than a thousand cheap ones.
- No page or body caps. An uncapped
limitparameter is an invitation to ask for a million rows. - Returning 403 instead of 429. Clients cannot tell a limit from a ban, so they retry or give up wrongly.
- Limits nobody monitors. A limit that fires constantly on real users is a bug, not protection.
- Forgetting GraphQL. Batched queries and deep nesting bypass per-request limits entirely.
If you run a small business, our small business cybersecurity checklist covers API and website controls alongside the basics.
The bottom line
Rate limiting is not a nice extra: it is OWASP API4, one of the ten most critical API risks. Without limits, one caller can take your API down or run up your bill, and no amount of authentication will help.
Measure your real traffic, limit per user and per key, tighten the limits on login and costly endpoints, cap page and body sizes, and return 429 with Retry-After. Then test it in staging and keep watching. You can check the public face of your own API with the free SSL checker.
Frequently asked questions
What is OWASP API4 Unrestricted Resource Consumption?
API4:2023 is the OWASP category for APIs that do not limit client interactions or resource consumption. Without limits, an attacker can send huge volumes of requests, ask for enormous pages, or trigger costly operations, causing denial of service or a large bill.
What is a good API rate limit?
There is no single correct number. The right limit depends on what a legitimate client does: a normal user, a sync job and a bulk importer have very different patterns. Measure real traffic first, then set limits above normal use and well below abuse.
Should I rate limit by IP or by user?
By user or API key first, and by IP as a second layer. Many users can share one IP behind an office network or a mobile carrier, and one attacker can use many IPs, so IP alone is neither fair nor effective.
What should an API return when rate limited?
Return HTTP 429 Too Many Requests, defined in RFC 6585, with a Retry-After header telling the client how long to wait. Do not return 403, which suggests permanent denial, and do not silently drop requests.
Does rate limiting stop credential stuffing?
It slows it down a lot, especially when limits are per account as well as per IP, and when login endpoints have tight limits and lockouts. Rate limiting alone does not stop it: also use multi-factor authentication, breached-password checks and monitoring.
Can rate limiting break legitimate clients?
Yes, if limits are too low or applied badly. A shared office IP, a bulk import job or a retry storm after an outage can all hit a limit. Set limits from measured traffic, give clear 429 responses with Retry-After, and provide a way for legitimate heavy users to request a higher quota.
Is rate limiting the same as throttling?
They are closely related. Rate limiting rejects requests above a quota, usually with a 429 response. Throttling slows requests down instead of rejecting them. Many systems combine both: throttle first, then reject when the client keeps going.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against the OWASP API Security Top 10 (2023 edition) and the OWASP Developer Guide.
How we write and fact-check →