Skip to content

n8n workflows

n8n HTTP Request 429s: honor Retry-After with Never Error and Wait

Turn 429 and 5xx responses in the n8n HTTP Request node into data, read Retry-After, wait the time the server asks for, and stop the run on 401, 402 or 403.

By Caitlin Sanders, AgentScraper team · Published

This article was drafted with AI assistance from the sources listed below and edited and published by the AgentScraper team. Disclosure: the AgentScraper API, which this article mentions, is this site's own product.

429 handling in n8n, node by node
  1. 1HTTP RequestNever Error on, Include Response Headers and Status on, Retry On Fail off.
  2. 2Decide (Code)Read the status code and Retry-After, count attempts, pick an action.
  3. 3SwitchOne output per action, Fallback Output set to Extra Output.
  4. 4WaitAfter Time Interval, amount from waitSeconds, unit Seconds, then back to Prepare.

Your workflow sends a list of URLs through the HTTP Request node. Somewhere around item 40 the API answers 429 Too Many Requests, the node turns red, and the run ends. You switch on Retry On Fail, and the next run still fails, just a few seconds later.

The problem is not the retry. It is the wait. A 429 can carry a Retry-After header that says how long to back off, and the built-in retry does not read it. This post builds the retry as visible n8n branches instead: the status comes back as data, a Code node decides, and a Wait node waits as long as the server asked.

Why Retry On Fail is the wrong tool here

Retry On Fail repeats the node with a fixed pause. The n8n rate-limit docs state its ceiling plainly: Max Tries is limited to five, and Wait Between Tries is limited to 5000 ms. If the server asks for 30 seconds, you can only wait 5.

Retry-After comes in two forms, and both need handling. It is either a number of seconds, such as 120, or an HTTP date, such as Wed, 21 Oct 2015 07:28:00 GMT. MDN lists it for 429, where it says how long to wait before the next request, and for 503, where it says how long the service is expected to be down.

So turn Retry On Fail off for this node and do the waiting yourself.

Step 1: make the HTTP Request node return failures as data

Open the HTTP Request node. Go to "Settings" and switch "Retry On Fail" off.

Go back to "Parameters". Under "Options", add "Response". Switch "Never Error" on. Switch "Include Response Headers and Status" on.

By default the node only succeeds on a 2xx code. With "Never Error" on, it succeeds whatever the code is. With "Include Response Headers and Status" on, it returns the status code and headers next to the body.

What you see: a 429 item no longer stops the run. It arrives in the output panel with its status code and headers next to the body.

Keep pacing in place too. Under "Options", add "Batching". Set "Items per Batch" and "Batch Interval" so you stay under the API's documented rate. The n8n docs use 1000 ms as the example Batch Interval, a 1-second wait between batches. Retries handle the 429 that still gets through; pacing keeps it rare.

Step 2: count attempts in a Prepare node

Each item needs to remember its URL and how many times it was tried. Put a Code node named "Prepare" in front of the HTTP Request node:

// Code node "Prepare"
return $input.all().map((item, i) => ({
  json: { url: item.json.url, attempt: item.json.attempt ?? 0 },
  pairedItem: i,
}));

Point the HTTP Request node's URL or body at {{ $json.url }}, as your API documents it.

What you see: every item leaves Prepare with attempt: 0. Items that come back through the retry loop keep their count.

Step 3: decide in one Code node

Add a Code node named "Decide" after the HTTP Request node. It reads the status, parses Retry-After in either form, and picks one action per item.

// Code node "Decide"
const MAX_RETRIES = 3;
const MAX_WAIT_S = 300; // longer waits go to the next run
const STOP = [401, 402, 403];
const out = [];
const items = $input.all();

for (let i = 0; i < items.length; i++) {
  const res = items[i].json;
  const job = $('Prepare').itemMatching(i).json;
  const attempt = job.attempt ?? 0;
  const code = res.statusCode;
  const headers = res.headers ?? {};
  const raKey = Object.keys(headers).find((k) => k.toLowerCase() === 'retry-after');
  const ra = raKey ? String(headers[raKey]).trim() : null;

  let action = 'done';
  let waitSeconds = 0;

  if (STOP.includes(code)) {
    action = 'stop';
  } else if (code === 429 || code >= 500) {
    if (attempt >= MAX_RETRIES) {
      action = 'next_run';
    } else {
      action = 'retry';
      if (ra && /^\d+$/.test(ra)) {
        waitSeconds = Number(ra);
      } else if (ra && !Number.isNaN(Date.parse(ra))) {
        waitSeconds = Math.ceil((Date.parse(ra) - Date.now()) / 1000);
      } else {
        waitSeconds = 2 ** attempt + Math.floor(Math.random() * 2);
      }
      waitSeconds = Math.max(1, waitSeconds);
      if (waitSeconds > MAX_WAIT_S) action = 'next_run';
    }
  } else if (code >= 400) {
    action = 'skip';
  }

  out.push({
    json: { url: job.url, attempt: attempt + 1, statusCode: code, action, waitSeconds, body: res.body },
    pairedItem: i,
  });
}
return out;

Without a Retry-After header, the backoff waits 1 to 2 seconds, then 2 to 3, then 4 to 5.

What you see: each item now carries action with one of done, retry, next_run, skip or stop.

The code assumes the full response arrives as statusCode, headers and body fields. Test the $('Prepare') lookup and those field names on a short list before a long one.

This follows the policy every guide on this site uses: retry 429, 5xx and CRAWL_LIVECRAWL_TIMEOUT up to 3 times with backoff, retry no other per-URL error in the same run, and stop the job on 402, 401 or 403. If your API reports per-URL failures inside a 200 response, add a branch on that field for the timeout tag. The full retry rules table lists every tag.

Step 4: route with Switch, and set the fallback

Add a Switch node after Decide. Set "Mode" to "Rules". Add one rule per action: {{ $json.action }} is equal to retry, stop, done, next_run and skip.

Open "Options" and add "Fallback Output". Set it to "Extra Output".

The default fallback is "None", which ignores any item that matches no rule. A typo in one rule would make rows disappear without an error. With "Extra Output", they land on a separate output you can see.

What you see: five rule outputs plus a fallback, and every item counted on exactly one of them.

Step 5: wait, loop back, or stop

Connect the retry output to a Wait node. Set "Resume" to "After Time Interval". Set "Wait Amount" to {{ $json.waitSeconds }} and "Wait Unit" to "Seconds". Connect the Wait node back to Prepare.

For waits under 65 seconds, n8n does not offload the execution data to the database. Longer pauses are offloaded and reloaded when the interval is over. The 300-second cap in Decide keeps a single run from sitting in Wait for long.

End the run on the stop output, with a message such as Stopped: account error. A bad key or empty balance fails every URL the same way, so the run should end here.

Send done, skip and next_run to your storage step, one row per URL with its status code and action. The next scheduled run picks up the next_run rows.

What you see: on a test list with one URL that returns 429, the execution view shows the item going through Wait, then back through Prepare with attempt: 1.

Status table

ResponseActionWhere it goes
2xxdoneStorage
429, 5xx, under 3 retriesretryWait, then Prepare
429, 5xx, retries used up or wait over 300 snext_runStorage, picked up later
401, 402, 403stopEnd the run
Other 4xxskipStorage

What this means for your workflow

  • Switch Retry On Fail off for the HTTP Request node. It cannot wait longer than 5000 ms.
  • Turn on "Never Error" and "Include Response Headers and Status", so the failure is data.
  • Parse Retry-After as seconds or as a date, and cap the wait.
  • Set the Switch fallback to "Extra Output", so no row vanishes.
  • Store one row per URL, so the next run can finish what this one left.

For the base workflow around this branch, see the n8n web scraping guide. If the HTTP step calls the AgentScraper API, the No-code recipes list the node values. Failed fetches cost 0 credits.

Frequently asked questions

Why not just use Retry On Fail in the n8n HTTP Request node for 429 errors?

Retry On Fail waits a fixed time between tries, and n8n limits it to five tries and 5000 ms between them. It does not read the Retry-After header, so a server that asks for 30 seconds gets retried too early.

How do I read the status code of a failed request in n8n?

Turn on Never Error so non-2xx responses do not fail the node, and turn on Include Response Headers and Status. The item then carries the status code and headers next to the body, and an IF, Switch or Code node can route on them.

What happens to a long wait in the n8n Wait node?

When a workflow pauses in the Wait node, n8n offloads the execution data to the database and reloads it when the interval has passed. For waits under 65 seconds it does not offload; the process keeps running.

Sources

  1. HTTP Request node (n8n docs) (Documentation)
  2. Handling API rate limits (n8n docs) (Documentation)
  3. Wait node (n8n docs) (Documentation)
  4. Switch node (n8n docs) (Documentation)
  5. Retry-After header (MDN) (Documentation)