Skip to content
Urlzee

API Rate Limiting Explained: 429 Errors and Retry-After

By Urlzee Team · Published · 7 min read

Rate limiting is how an API caps the number of requests one client can make in a period of time. When you go over, the server answers with HTTP 429 Too Many Requests and usually a Retry-After header saying how long to wait. The fix is to wait that long, then send requests more slowly.

Why do APIs limit requests?

To stay available and fair. A server has finite capacity, and without limits one client could use all of it.

  • Protection from accidents. A loop with a bug can send thousands of requests a second. A limit turns that into a string of 429s instead of an outage.
  • Fairness. Every customer shares the same infrastructure. Limits stop one heavy user from slowing everyone else.
  • Abuse resistance. Limits slow down credential guessing, scraping and other bulk misuse.
  • Pricing. Limits are how plans differ. More volume costs more to serve.

A 429 is therefore not an error in your request. It is a status message about your pace.

What is the difference between a rate limit and a quota?

A rate limit controls speed; a quota controls total volume. Most APIs apply both, and they fail differently.

Rate limitQuota
PeriodSeconds or minutesDay or month
PurposeSmooth out burstsCap total usage for a plan
When you hit itWait a short timeWait for the period to reset, or upgrade
Typical Retry-AfterSecondsCould be hours or days

The Urlzee API has both, set by plan:

PlanRequests per minuteRequests per monthLinks per month
Free1010050
Pro6010,0005,000
Business300100,00050,000

Exceeding any of them produces the same response: status 429 with the error code rate_limited. The message and the size of Retry-After tell you which limit you met.

How do you read rate limit headers?

Well-behaved APIs tell you where you stand on every response, not only when you fail. The header names vary between services. Urlzee sends four:

HeaderMeaning
X-RateLimit-LimitRequests allowed per minute on your plan
X-RateLimit-RemainingRequests left in the current minute
X-Quota-LimitRequests allowed per month on your plan
X-Quota-RemainingRequests left this month

You can see them with curl's -i flag:

curl -i "https://urlzee.com/api/v1/links?limit=1" \
  -H "Authorization: Bearer $URLZEE_API_KEY"

When X-RateLimit-Remaining reaches 0, the next request in that minute will be refused. A client that watches this header can slow down before it is told to.

What does Retry-After tell you?

How long to stay quiet. The HTTP specification allows two formats:

Retry-After: 30
Retry-After: Wed, 02 Dec 2026 07:28:00 GMT

The first is a number of seconds. The second is a date and time after which you may retry. Urlzee sends seconds. A client written for more than one API should accept both. MDN has a concise reference for the Retry-After header.

A full rate-limited response from the Urlzee API looks like this:

HTTP/1.1 429 Too Many Requests
Retry-After: 21
Content-Type: application/json

{ "error": { "code": "rate_limited", "message": "Too many requests. Please slow down and try again shortly." } }

Honour the number. Retrying sooner does not help, and on many APIs, Urlzee included, refused requests still count against the window.

How do servers count requests?

There are a few standard algorithms. You do not need to know which one an API uses in order to be a good client, but it explains the behaviour you see.

  • Fixed window. Count requests in clock-aligned blocks, such as each minute. Simple and cheap. The counter resets at the boundary, so Retry-After is the time left in the current block. Urlzee's per-minute limit works this way.
  • Sliding window. Count requests in the last 60 seconds, measured continuously. Smoother, because there is no boundary to burst across.
  • Token bucket. Each client has a bucket that refills at a steady rate. Each request spends a token. Short bursts are allowed up to the bucket's size, and the long-run rate is capped by the refill.
  • Leaky bucket. Requests join a queue that drains at a fixed rate. Bursts are flattened instead of rejected, until the queue is full.

How should your code handle a 429?

Wait, retry a limited number of times, and give up cleanly. The steps:

  1. Detect status 429 (and usually 503, which can also carry Retry-After).
  2. Read Retry-After. If present, wait that long.
  3. If it is absent, use exponential backoff: wait 1 second, then 2, then 4, and add some randomness so that many clients do not all retry at the same instant.
  4. Stop after a few attempts.
  5. Refuse to wait for an unreasonable time. A Retry-After of several hours means a quota is exhausted, and the right response is to report it.

Here is that logic for Node.js 18 or later, with no dependencies:

import { setTimeout as sleep } from "node:timers/promises";

function retryDelayMs(res, attempt) {
  const header = res.headers.get("retry-after");
  if (header) {
    const seconds = Number(header);
    if (Number.isFinite(seconds)) return seconds * 1000;
    const date = Date.parse(header);
    if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
  }
  // No usable header: exponential backoff with jitter, capped at 30 seconds.
  const base = Math.min(30_000, 1000 * 2 ** (attempt - 1));
  return base / 2 + Math.random() * (base / 2);
}

export async function fetchWithRetry(url, init = {}, { attempts = 4, maxWaitMs = 60_000 } = {}) {
  for (let attempt = 1; ; attempt++) {
    const res = await fetch(url, init);
    const retryable = res.status === 429 || res.status === 503;
    if (!retryable || attempt === attempts) return res;

    const wait = retryDelayMs(res, attempt);
    if (wait > maxWaitMs) return res; // quota exhausted: let the caller decide

    await res.body?.cancel();
    await sleep(wait);
  }
}

Use it exactly like fetch:

const res = await fetchWithRetry("https://urlzee.com/api/v1/links", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.URLZEE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: "https://example.com/launch" }),
});

The function returns the final response whatever its status, so the caller still checks res.ok. Complete clients built on the same idea are in how to shorten URLs with JavaScript and how to shorten URLs with Python.

How do you avoid hitting the limit in the first place?

Retries are a safety net. A client that regularly leans on them is going too fast.

  • Send requests in sequence. Launching fifty requests at once with Promise.all or a thread pool will exceed a 10-per-minute limit instantly. A plain loop is the simplest throttle.
  • Pace to the limit. Divide the window by the allowance. At 10 requests a minute, leave about 6 seconds between calls. At 60 a minute, about 1 second. At 300 a minute, about 200 milliseconds.
  • Watch the remaining count. If X-RateLimit-Remaining is 0, pause before the next call instead of sending one that is bound to fail.
  • Cache what does not change. A link's id and short_url never change once created. Store them in your own database instead of listing links again.
  • Do not poll for statistics. Click counts move slowly compared with a per-minute limit. Fetch them on a schedule, such as hourly or daily.
  • Count every call. On Urlzee, listing and stats requests draw on the same monthly quota as link creation.

What mistakes make rate limiting worse?

  • Retrying immediately in a tight loop. Each retry is another counted request, so the client keeps itself locked out.
  • Retrying every error. A 400, 401 or 422 will fail the same way forever. Only 429 and some 5xx responses are worth retrying. The HTTP status codes guide explains which.
  • No retry cap. A job that retries without limit can run for days and hide the real problem.
  • Sharing one key across many jobs. Limits apply per account, so separate scripts compete for the same allowance. Schedule them at different times.
  • Ignoring the body. The error message says whether you hit the per-minute rate or the monthly quota. Log it.

If your workload simply needs more than your plan allows, no amount of clever retrying will change that; the allowances for each tier are on the pricing page, and the request format is in the API documentation.

Frequently asked questions

What does HTTP 429 Too Many Requests mean?
It means you have sent more requests than the server allows in a given period. Nothing is wrong with the request itself; the server is asking you to slow down and try again later.
What is the Retry-After header?
Retry-After tells a client how long to wait before sending another request. Its value is either a number of seconds, such as 30, or an HTTP date. Servers commonly send it with 429 and 503 responses.
How do I fix a 429 error?
Wait for the time given in Retry-After, then retry. To stop it recurring, send requests sequentially instead of in parallel, space them out to match the documented limit, cache results you already have, and upgrade your plan if you need more volume.
What is the difference between a rate limit and a quota?
A rate limit caps how fast you can call an API, typically per second or per minute. A quota caps the total over a longer period, such as a month. You can be within your quota and still hit the rate limit by sending requests in a burst.