Itnetic logo Itnetic Technologies
PlatformLogsNetworkPricing
Log inStart free
PlatformLogsNetworkPricing
Log inStart free

Learn · API protection

How to protect an API from DDoS attacks.

Browser challenges are useless against machine traffic — and fatal to it. Protecting an API means identifying clients and bounding what each one can cost you.

Updated July 27, 2026 · Itnetic team — reviewed by Petr Chlíbek, founder

Key takeaways

  • API clients cannot solve browser challenges or store cookies, so website-shaped DDoS protection either breaks your integrations or waves the attack straight through.
  • API mitigation asks whether a client is identified and within budget, not whether it is human — which makes a credential-keyed rate limit far stronger than an IP-keyed one.
  • Answer overload with 429 and a Retry-After header, never a redirect or CAPTCHA; a machine client that cannot parse the response retries harder and deepens the flood.
  • Cap request cost as well as request rate: pagination limits, GraphQL complexity limits, query timeouts and edge caching decide how much damage one request can do.

An API is a DDoS target with its defenses removed

Most Layer 7 mitigation leans on one convenient fact: real website visitors arrive in browsers. A lightweight challenge asks the client to run a little JavaScript and hand back a signed cookie, and anything that cannot do that was never a customer.

APIs have no such tell. curl, an SDK, a mobile app, a CI pipeline and a payment webhook are all legitimate clients, and not one of them can solve a browser challenge or keep a cookie jar. Point browser-shaped protection at /api/ and you get the worst of both worlds: honest integrations break the moment protection tightens, while an attacker who simply ignores the redirect keeps hammering the endpoint.

That is the whole problem in one sentence. API mitigation cannot ask "is this a human?" — it has to ask "is this client identified, and is it staying inside its budget?"

What changes between a website and an API

Website trafficAPI traffic
Legitimate clientA browsercurl, SDK, mobile app, webhook, CI job
Can solve a challengeYes, invisiblyNo, ever
Stores cookiesYesUsually not
Identity signalBrowser verification, navigation rhythmAPI key, bearer token, signed webhook header
Expected error formatAn HTML pageJSON body with a correct status code
Cheapest defenseEdge cache plus challengePer-client rate limits plus cost caps

How API DDoS attacks actually look

  • Flat endpoint floods — thousands of requests per second at a single route, spread across rotating addresses, at a rate no real client would ever produce.
  • Expensive-query abuse — deep pagination (?page=48000), an unbounded limit, wide date ranges or sort-by-everything parameters that turn one request into a full table scan.
  • GraphQL query bombs — one syntactically valid query with nested relations that expands into thousands of resolver calls. Tiny request, enormous cost.
  • Token grinding and credential stuffing — automated attempts against /auth/login or /oauth/token using leaked password lists. An account-takeover attempt and a flood on your most expensive endpoint at the same time.
  • Webhook and callback floods — your public callback URL is documented by definition, and replaying captured payloads is trivial if you do not verify signatures.
  • Cache-busting parameters — randomized query strings crafted so every request misses cache and lands on your origin.
  • Accidental self-DDoS — one client shipping a retry loop with no backoff. Not malicious, indistinguishable from an attack, and the fix is the same.

The common thread is the cost asymmetry behind every Layer 7 attack: the attacker spends one cheap HTTP request, you spend database time. API endpoints map directly onto expensive operations, which makes them the highest-leverage target on your infrastructure.

Step 1 — Identify the client before you limit it

A rate limit is only as good as the key it counts against, and the IP address is both the default choice and the weakest one: a botnet has thousands of addresses, while a corporate NAT or a mobile carrier puts thousands of your real users behind a single one.

Prefer, in order:

  1. An authentication credential — API key, bearer token or account ID. Hash it before using it as a limiter key, so the raw secret is never stored.
  2. A verified webhook signature — check the signature and limit the sender, not the address it came from.
  3. The IP address — the fallback for genuinely anonymous endpoints, and a good reason to keep those endpoints cheap.

Requiring a key on every non-public route is the highest-value change available to you. It converts anonymous flooding into an identified client exceeding a documented budget — a problem with an obvious, automatable answer.

Step 2 — Rate-limit in a way machines can obey

  • Token bucket per client, so a legitimate burst is allowed and a sustained flood is not. Far friendlier to real SDK usage than a fixed window that resets on the second.
  • A zone-wide ceiling on top of per-client limits, so ten thousand freshly registered keys cannot each behave "legally" and still take you down.
  • Separate budgets per cost class. GET /v1/status and POST /v1/reports do not belong on the same limit.
  • Answer with 429 and a Retry-After header, plus RateLimit-Limit and RateLimit-Remaining if you can. A well-behaved client backs off on its own; a response it cannot parse turns your mitigation into an outage.
  • Never send a challenge page, CAPTCHA or 302 to an API path. A machine client reads that as a corrupt response, retries harder, and joins the flood you were trying to stop.

Step 3 — Make each request cheaper to serve

Rate limits bound how many requests arrive. Cost caps bound how much damage each one can do.

  • Cap limit and per_page, reject unbounded ranges, and use cursor pagination so deep offsets stop being expensive in the first place.
  • Enforce query depth and complexity limits on GraphQL, and disable introspection in production.
  • Set hard timeouts on database queries and upstream calls, so one slow path cannot pile up connections until the pool is gone.
  • Cache what is cacheable — public GETs, reference data, computed aggregates — with short TTLs at the edge. Every cache hit is a request your origin never serves, which is why a CDN is also attack armor for APIs.
  • Move genuinely expensive work into a queue and return 202 with a job URL, so a burst becomes a backlog instead of an outage.

Step 4 — Roll it out without breaking your clients

  1. Measure first. Pull p95 and p99 request rates per client from your logs. Real limits come from real percentiles, not round numbers.
  2. Run in log-only mode for a week or two and watch who would have been limited. It is usually one integration with a broken retry loop, not an attack.
  3. Set the limit above your noisiest honest client, then enforce it.
  4. Document the limits and the 429 contract in your API reference, so integrators handle it correctly before they ever hit it.
  5. Alert on limit hits, not only on downtime. A client crossing its budget is the earliest warning you get that something has changed.

Step 5 — Lock the origin down

None of the above matters if your API can be reached directly. Attackers look up the hostname's DNS history, find the server address, and skip your filtering edge entirely. Firewall the origin so it accepts traffic only from your mitigation network, and close the usual leaks — unproxied subdomains, mail records, certificate transparency logs. The full walkthrough is in how to hide your origin IP address.

How Itnetic protects API paths

Our default defense is a browser challenge, which is exactly the wrong instrument for machine traffic — so API paths get their own pipeline. You mark path prefixes such as /api/ or /graphql as an API zone, and matching requests are treated as machine traffic end to end: never challenged, never given tag cookies, and never counted by the browser-oriented flood detectors that would otherwise read a cookieless SDK as an attacker.

Protection inside the zone is exactly what this article argues for. Per-client token-bucket limits keyed by a header you choose — Authorization is the usual pick, hashed so the raw credential is never stored — with an IP fallback for anonymous routes, plus a zone-wide flood ceiling that arms a short attack window. Rate-limited clients get a 429 with Retry-After, never HTML. For the attack window you pick the posture: block flagged attacker fingerprints, additionally reject requests missing your key header, or log only while you tune. Invalid zone configuration fails open to the normal web pipeline, so a bad rule never takes your API down.

Every verdict lands in per-request logs alongside the client fingerprint and the rule that fired — which is what you need when an integrator asks why their nightly job started getting 429s. Attack traffic is never metered against your bandwidth quota, so being attacked does not produce an invoice; see pricing.

Itnetic's DDoS protection covers websites and APIs on the same edge network, enabled with two DNS records. If you want the background first, start with what DDoS mitigation is.

FAQ

Quick answers

Can a WAF or a browser challenge protect an API?

A WAF helps against malformed and malicious individual requests, but not against a flood of valid ones. A browser challenge is worse than useless on an API path: legitimate clients — curl, SDKs, mobile apps, webhooks — cannot solve it, so you take your own integrations offline while attackers ignore the redirect. API paths need identity, rate limits and signature-based filtering instead.

What rate limit should I set for my API?

Derive it from your own data rather than a round number: measure p95 and p99 request rates per client over a normal week, set the limit comfortably above your noisiest honest client, and give expensive endpoints their own lower budget. Run in log-only mode first so you discover which real integrations would break before enforcement does it for you.

What should a rate-limited or overloaded API return?

A 429 with a Retry-After header for rate limiting, and a 503 with Retry-After for genuine overload — both with a JSON body matching the rest of your API. Never return an HTML challenge page, a CAPTCHA or a 302 redirect: a machine client cannot interpret them, so it retries immediately and makes the flood worse.

How do I protect a public API with no authentication?

Keep anonymous endpoints deliberately cheap and cacheable, apply IP-keyed limits knowing they are imperfect, and add a zone-wide flood ceiling so aggregate volume is bounded even when no single address stands out. If an endpoint is expensive enough that abuse hurts, it is expensive enough to require a key.

Is GraphQL harder to protect from DDoS than REST?

Yes, because request count no longer correlates with cost — one valid query with nested relations can expand into thousands of resolver calls. Rate limits alone are not enough: enforce query depth and complexity limits, cap list sizes, set resolver timeouts and disable introspection in production, then rate-limit on top.

Keep reading

01

What is a DDoS attack?

A distributed denial-of-service (DDoS) attack overwhelms a website or API with traffic from many machines at once, until real visitors can no longer get through.

02

What is a Layer 7 DDoS attack?

Layer 7 (application-layer) DDoS attacks imitate legitimate visitors instead of flooding the network — which is exactly why traditional defenses miss them.

03

How to stop a DDoS attack on your website.

A practical, ordered checklist for the moment your site goes down — and for making sure the next attack never reaches it.

04

What is DDoS mitigation?

DDoS mitigation is the process of spotting attack traffic and dropping it before it reaches the resource an attacker is trying to exhaust — bandwidth, connections, or your application itself.

05

How to protect WordPress from DDoS attacks.

A WordPress page costs you a database round trip and a PHP worker. It costs the attacker one HTTP request. That asymmetry — not bandwidth — is what takes WordPress sites offline.

06

How to hide your origin IP address.

DDoS mitigation only works if your server cannot be reached any other way. An exposed origin IP is the most common reason protection is in place and the site still goes down.

07

What is a CDN?

A content delivery network (CDN) stores copies of your website on servers around the world, so every visitor is served from the location nearest to them.

Protect my website freeHow our protection works
Itnetic logo Itnetic Technologies

Advanced DDoS mitigation and web performance solutions for modern businesses. Protect your infrastructure across multiple regions.

Product

  • DDoS Mitigation
  • Web CDN
  • Network
  • Pricing

Resources

  • Learn
  • Changelog
  • FAQ
  • Status

Company

  • Founder
  • Contact
Petr ChlíbekIČO: 21210756Neplátce DPH
© 2026 Itnetic Technologies. All rights reserved.
Terms of ServicePrivacy PolicyCookie PolicyDPA

We use essential cookies to run and secure the site. With your consent we also use Umami analytics (self-hosted, no cross-site tracking) to understand usage. Cookie Policy