AI summary
What to do in n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API. when an API call fails: timeouts, 401The HTTP status for Unauthorized: the server didn't accept your credentials, or you sent none. and 403The HTTP status for Forbidden: the server understood the request and refuses to carry it out., 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time. with Retry-AfterA response header that says how long to wait before trying again, in seconds or as a date., empty results, and safely retrying requests that change server data.
- Retry timeouts on reads, stop on 401The HTTP status for Unauthorized: the server didn't accept your credentials, or you sent none. and 403The HTTP status for Forbidden: the server understood the request and refuses to carry it out., wait on 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time., and accept an empty result as an answer.
- Retry On FailA setting on every n8n node. When the node fails, n8n runs it again, a set number of times with a set wait in between. waits at most 5 seconds between tries and ignores Retry-AfterA response header that says how long to wait before trying again, in seconds or as a date., so read that header yourself.
- A request that changes server data may have worked even if it timed out. Use an idempotency keyA unique value sent with a request, so the server can recognize a repeat and return the first result instead of doing the work again., look it up first, or send it to a person.
A 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time., a 403The HTTP status for Forbidden: the server understood the request and refuses to carry it out. and an empty list can all look like “the API call didn’t work” from inside an n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API. workflow. They need different handling.
In n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API., each step of a workflow is a node. Every node has a setting called Retry On FailA setting on every n8n node. When the node fails, n8n runs it again, a set number of times with a set wait in between. that repeats a failed call. Turn it on for everything and it gets most of these cases wrong.
I built n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API. workflows between about 10 university library systems and an AI chatbot. Each library had its own API, authentication and response format, so the same failure looked different in each one. That’s why I decide by failure type, not by API. Pick a failure here:
Bounded retries with a delay. For writes, check whether repeating the operation is safe.
Stop retrying the same credentials. Check authentication and permissions.
Wait according to the service rate limit and Retry-After value when supplied.
If the request succeeded, return a valid empty answer. Keep it separate from service failure.
Timeouts: retry reads a limited number of times
A timeout doesn’t tell you whether the server did the work. For a GET that doesn’t matter, so retry a few times with a delay and then give up.
A write, a request that creates or changes data, is different. For that, skip to the last section.
401 and 403: stop
A 401The HTTP status for Unauthorized: the server didn't accept your credentials, or you sent none. means the credentials were refused. If the token you send to prove who you are is no longer valid, try getting a new one without signing in again, if the API allows it. Do that once, then retry the request once. RFC 9110The standard that defines HTTP: its methods, status codes and headers, and when a client may repeat a request. allows repeating the request with a new or replaced Authorization header.
A 403The HTTP status for Forbidden: the server understood the request and refuses to carry it out. means the server understood the request and refuses it. If you sent credentials, it found them insufficient. In that case, RFC 9110The standard that defines HTTP: its methods, status codes and headers, and when a client may repeat a request. says a client shouldn’t automatically repeat the request with the same credentials. More tries only use up your rate limitHow many requests an API lets you send in a given time, for example 100 a minute..
I’d end the run with a Stop And Error node, so the error workflowA separate n8n workflow that runs when another workflow fails. You pick it in that workflow's settings. can alert someone with the API name and status.
429: wait as long as the API asks
A 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time. means you’ve sent the API too many requests. The response may include a Retry-After header that says how long to wait. The value is either a number of seconds, such as 120, or a date, such as Fri, 13 Nov 2026 09:00:00 GMT.
Retry On FailA setting on every n8n node. When the node fails, n8n runs it again, a set number of times with a set wait in between. can’t follow it. According to n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API.’s page on rate limitHow many requests an API lets you send in a given time, for example 100 a minute.s, Retry On FailA setting on every n8n node. When the node fails, n8n runs it again, a set number of times with a set wait in between. waits at most 5 seconds between tries and tries at most five times. The same page says the HTTP Request node doesn’t honor Retry-After. You have to read the header yourself.
The chat on this site sends the same response from the other side: a 429 with Retry-After when one visitor asks too often.
Then think about who’s waiting. Imagine a student asks the chatbot about a book and the API answers Retry-After: 3600. Nobody stays in a chat for an hour. Tell them the catalog isn’t available right now and stop. A nightly sync can actually wait.
Empty results: accept them
A successful search with no matches is an answer. If you treat it as a failure, the chatbot says something went wrong when the library just doesn’t have the book.
“Empty” looks different from one API to another. It could be [], null, or a 404 on a lookup. Some APIs even return 200 with an error in the body, and that one should become a failure, not an empty result.
I’d turn each API’s version of “empty” into one shape, once per integration, before the shared part of the workflow. A 404 that means “nothing found” then reaches the next step as a 200 with an empty body.
Reading the status in n8n
Turn on Never Error and Include Response Headers and Status in the HTTP Request node. The node now reports success for any status, so Retry On FailA setting on every n8n node. When the node fails, n8n runs it again, a set number of times with a set wait in between. won’t fire on a 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time.. What happens next is up to the steps you add after it. I’ll set those up below.
The decision itself goes in a Code node, which runs your own JavaScript. In the mode used below, the code runs once for each item. In n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API., an item is one record the workflow is working on, here one request and its response.
A timeout has no status code, and Never Error doesn’t catch it. So also set the node’s On Error setting to Continue (using error output). A failed request then leaves through a second output instead of stopping the run. Connect that output to the same Code node.
I tried this in n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API. 1.110.1 with the node’s timeout set to 1 second. The item on the error output kept the fields it came in with and got an error field, with the message timeout of 1000ms exceeded. It has no statusCode, so the code handles it the same way as a server error. A server error is a 5xx status, such as 500 or 503: the server itself failed.
The code also needs to know whether a request is safe to send again. An earlier node sets safeToRepeat for that. It’s true for reads. It’s also true for two kinds of writes.
The first kind carries an idempotency keyA unique value sent with a request, so the server can recognize a repeat and return the first result instead of doing the work again.: a unique value you send with the request, so the server can recognize a repeat and return the first result instead of doing the work twice. The second kind is a write you can look up first. Run that lookup before each retry, and send the POST again only if it finds nothing. The section on writes below covers both.
The code retries a 5xx or a timeout only when safeToRepeat is true. Otherwise the item goes to review, which means a person checks it.
Every other status, 401The HTTP status for Unauthorized: the server didn't accept your credentials, or you sent none. and 403The HTTP status for Forbidden: the server understood the request and refuses to carry it out. included, becomes stop. This code doesn’t refresh tokens. If you refresh tokens on a 401The HTTP status for Unauthorized: the server didn't accept your credentials, or you sent none., give that its own branch before this node.
// n8n Code node, mode: Run Once for Each Item.
// Assumes a previous "Prepare request" node sets safeToRepeat.
const { statusCode: status, headers = {}, body } = $json;
const { safeToRepeat } = $("Prepare request").item.json;
function retryAfterSeconds(value, fallback = 60) {
if (!value) return fallback;
if (/^\d+$/.test(value)) return Number(value);
const date = Date.parse(value);
if (Number.isNaN(date)) return fallback;
return Math.max(0, Math.ceil((date - Date.now()) / 1000));
}
let action = "stop";
if (status >= 200 && status < 300) action = "accept";
else if (status === 429) action = "wait";
// No status: the item came from the timeout (error output) branch.
else if (status === undefined || status >= 500) {
action = safeToRepeat ? "retry" : "review";
}
return {
json: {
action,
status,
body,
waitSeconds: retryAfterSeconds(headers["retry-after"]),
},
};I ran this node in n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API. 1.110.1 against httpbinA public test API at httpbin.org. A call to /status/429, for example, gets back a 429 response., with safeToRepeat set to true. One request got each status below, and a fifth took longer than the node’s 1-second timeout. httpbinA public test API at httpbin.org. A call to /status/429, for example, gets back a 429 response.’s responses here have no body, so there’s no body field in what came out:
{"action":"wait","status":429,"waitSeconds":60}
{"action":"retry","status":503,"waitSeconds":60}
{"action":"stop","status":403,"waitSeconds":60}
{"action":"accept","status":200,"waitSeconds":60}
{"action":"retry","waitSeconds":60}httpbinA public test API at httpbin.org. A call to /status/429, for example, gets back a 429 response.’s 429The HTTP status for Too Many Requests: you sent more requests than the API allows in a given time. has no Retry-After header, so the wait fell back to 60 seconds.
Both tests ran on 1.x. I haven’t rerun them on 2.x, but n8nAn automation tool you can host yourself. You build a workflow from nodes, and each node does one step, such as calling an API.’s current docs list the node settings above under the same names.
Send action into a Switch node, which sends each item down a branch by that value. The wait and retry branches loop back through a Wait node that takes its duration from waitSeconds. Both branches need an attempt counter, or a stuck API keeps the run going forever.
I prefer keeping this decision in one small Code node over a chain of IF nodes. Logic spread across nodes gets hard to read, and one Code node is easy to test separately.
Writes: a timeout might mean it worked
A POST that timed out is the risky case. The server may have saved the record, for example a hold on a library book, even though your workflow never got the answer, and then a retry saves it twice.
A request is idempotent when sending it twice has the same effect as sending it once. RFC 9110The standard that defines HTTP: its methods, status codes and headers, and when a client may repeat a request. counts PUT and DELETE as idempotent, along with methods like GET that only read. It says a client shouldn’t automatically retry anything else unless it knows that’s safe.
So I’d go in this order:
- If the API supports an idempotency keyA unique value sent with a request, so the server can recognize a repeat and return the first result instead of doing the work again., use one. Stripe’s
Idempotency-Keyheader is a good example. Generate the key once, before the first attempt, and keep it with the item. A key that changes on each try protects nothing. - If it doesn’t, send your own reference: a unique ID you generate and save in a field the API lets you search by. Look it up before repeating.
- If you can do neither, stop and send it to a person. A manual check is cheaper than a duplicate record.
A consumer that reads messages from a queue has the same problem. I wrote about how to handle it in a queue consumer too.
