Articles

How to rate-limit an API per IP without writing code

Rate-limit an API per IP, API key or JWT subject with one edge rule; callers over the limit get 429 before your app wakes. Compared with Vercel and Cloud Run.

Updated

On Gregale, one edge rule rate-limits your API per client IP without any code: gregale edge rule create --app my-api --kind throttle --match-host @app --match-path '/api/**' --throttle-key-by ip --throttle-requests-per-second 5 --throttle-burst 20. A caller over the limit gets 429 from Gregale's edge, before the request reaches your app, so abusive traffic never wakes it or adds running time. Edge rules are in beta on every plan, Free included.

Limit each IP

bash
gregale edge rule create --app my-api --kind throttle \
  --match-host @app --match-path '/api/**' \
  --throttle-key-by ip --throttle-requests-per-second 5 --throttle-burst 20

Each client IP gets a token bucket that refills at 5 requests a second and holds 20, so a client can burst to 20 requests and then keeps a steady 5 a second. IPv6 clients are grouped by /64, so one machine can't dodge the limit by rotating addresses inside its block.

  • --match-host @app covers every host the app serves, custom domains included.
  • --match-path '/api/**' covers /api and everything beneath it; use '/**' for every path.
  • The limit holds for the whole app: buckets are counted across every gateway that serves it, not per server.

What a limited caller sees

A request that finds its bucket empty gets 429 with the code rate_limited. Responses on the route carry X-RouteRateLimit-Limit, X-RouteRateLimit-Remaining, X-RouteRateLimit-Reset and X-RouteRateLimit-Policy, so a well-behaved client can slow down before it hits the limit.

Try it before you enforce it

Start the rule in log mode: it counts what it would limit and refuses nothing.

bash
gregale edge rule create --app my-api --kind throttle --mode log \
  --match-host @app --match-path '/api/**' \
  --throttle-key-by ip --throttle-requests-per-second 5 --throttle-burst 20

gregale edge rule events --app my-api --outcome logged   # who would have been limited
gregale edge rule review --app my-api                    # log-mode rules that look ready

When the logged requests look like abuse and not your own users, switch the rule to enforce.

Limit by something other than IP

--throttle-key-byOne bucket per
ipclient IP (IPv6 by /64)
api_keyAPI key
consumer_idAPI consumer, across its rotated keys
jwt_subjectJWT sub
countryclient country
compositeup to 4 fields, such as ip and header:<name>
nonethe whole route (every caller shares one bucket)

To slow down password guessing without limiting people who sign in correctly, count only failed sign-ins:

json
{
  "kind": "throttle",
  "match_host": "@app",
  "match_path": "/login",
  "action": {
    "requests_per_second": 0.1,
    "burst": 5,
    "key_by": "composite",
    "key_fields": ["ip", "header:x-username"],
    "count_statuses": [401]
  }
}

With count_statuses: [401], only responses with status 401 use a token: five wrong passwords for one username from one IP, then one try every 10 seconds.

How other platforms compare

PlatformPer-IP rate limiting without code
GregaleA throttle edge rule per IP, API key, JWT subject or a mix; limited requests never reach the app
VercelWAF rate limiting on all plans: 1 rule on Hobby and 40 on Pro, fixed window; token bucket on Enterprise; usage-based on Pro
Google Cloud RunCloud Armor rate limiting, which runs on an external Application Load Balancer; restrict ingress so the default URL can't bypass it
RenderNetwork-level DDoS protection; Render says application-level rate limiting is the defense to add yourself
RailwayNo built-in rate limiting; Railway staff point to the X-Real-IP header for limiting in your app
Fly.ioFly staff say Fly.io doesn't have rate limiting built in

Checked against each vendor's public documentation and forum answers on November 27, 2026: Vercel WAF rate limiting, Cloud Armor rate limiting, How Render handles DDoS attacks, Railway: IPs and rate limiting, Fly.io community: blocking IPs that send too many requests.

Pricing

Rate limiting costs nothing extra, and refused requests add no running time. Each plan caps how many throttle rules an app can have and how loose a rule can be; a throttle rule can only tighten the plan's limit:

PlanMonthlyThrottle rules per appMax rate (requests/s)Max burstBuckets per rule
Free$01520100
Hobby$105201001,000
Pro$30251005005,000
Scale$991005002,00010,000

See Edge rules and Gregale pricing.

Questions

How do I rate-limit an API per IP without code?

On Gregale, create a throttle edge rule keyed by IP: gregale edge rule create --app my-api --kind throttle --match-host @app --match-path /api/** --throttle-key-by ip --throttle-requests-per-second 5 --throttle-burst 20. Callers over the limit get 429 rate_limited from the edge.

Do rate-limited requests wake my app or cost money?

No. A refused request is answered at Gregale’s edge, so the app never wakes for it and it adds no running time.

Is the rate limit per server or for the whole app?

For the whole app. Buckets are counted across every gateway that serves it, not per gateway.

Can I limit only failed logins?

Yes. With count_statuses set to [401], every request is admitted while the bucket has a token, but only 401 responses use one, so failed sign-ins are limited and successful ones are not.

What are the rate limit plan limits?

Throttle rules per app: 1 on Free, 5 on Hobby, 25 on Pro and 100 on Scale. A rule’s rate can be at most 5, 20, 100 and 500 requests a second, and its burst 20, 100, 500 and 2,000.