Response status handling for failed public profile lookups comes down to one decision per code: wait for Retry-After on 429 and 503, back off and retry on 500, 502 and 504, queue unavailable for later, and never retry 401, 422 or gone. This post turns that into working code for ProfileHunt's LinkedIn profile API, in JavaScript and Python, for single calls and for batch items that come back failed.
Every failed lookup is free with ProfileHunt, so a retry never costs twice. What a retry does cost is time and rate limit, which is why the handling matters. For the bigger picture, see what a LinkedIn profile API is.
Key takeaways
- One matrix decides everything. Each status maps to exactly one action: done, retry soon, retry later, fix the input, or stop the job.
- Use exponential back-off with jitter for 5xx. Double the wait each attempt, cap it, and add randomness so workers don't retry in step.
- Honor
Retry-Afteron 429 and 503. It tells you exactly how many seconds to wait. On429it counts to the next clock minute. - 402 stops the job, not the request. Out of credits is true for every request that follows, so pause the whole pipeline.
- Batch
faileditems go into a later batch. They were already tried several times; send them again later, not straight away.
The retry matrix
Here is every outcome of POST /v1/profile and the batch API, reduced to the action your client takes. What each code means is covered in the status codes reference; this table is only about behavior.
| Outcome | Action | Wait |
|---|---|---|
200 ok | Save the profile. | None |
200 gone | Mark the record; don't retry. | None |
200 unavailable | Queue for a later retry. | Minutes to hours |
401 unauthorized | Stop. Fix the key. | None |
402 insufficient_credits | Stop the whole job. Top up. | Until topped up |
422 invalid_url / invalid_batch | Don't retry. Fix the input. | None |
429 rate_limited | Retry the same request. | Retry-After seconds |
503 temporarily_unavailable | Retry the same request. | Retry-After seconds |
500 internal, 502 upstream_failed, 504 timeout | Retry with back-off. | 1s, 2s, 4s… capped |
Batch item failed | Resend in a later batch. | Minutes or more |
Batch item invalid_url | Fix the input. | None |
Batch item duplicate | Copy the earlier result for the same profile. | None |
404 not_found on batch poll | Stop polling; the id is wrong, another workspace's, or older than 30 days. | None |
Three groups fall out of it. Retry soon: 429, 503, 500, 502, 504. Retry later: unavailable and failed. Never retry as-is: everything else.
Exponential back-off with jitter
For 500, 502 and 504, ProfileHunt's errors reference says to wait a few seconds and try again, backing off if it keeps failing. Exponential back-off does that: wait 1 second, then 2, then 4, doubling each time up to a cap. Jitter multiplies each wait by a random factor, so ten workers that failed at the same moment don't all retry at the same moment too.
The formula used below is min(2^attempt, 30) × random(0.5, 1) seconds: a wait between 1 and 2 seconds after the first failure, between 2 and 4 after the second, and never more than 30. Five attempts is a sensible cap. All of these retries are free, because a 5xx never uses a credit.
Honoring Retry-After on 429 and 503
For 429 and 503, don't guess: read the Retry-After header and sleep that many seconds. The header is defined in RFC 9110, and 429 itself in RFC 6585.
ProfileHunt's rate limit is 60 requests a minute per key, and it resets at the start of each clock minute. So Retry-After on a 429 is the number of seconds until the next minute starts, often well under 60. Every counted request also carries X-RateLimit-Remaining, which lets a client slow down before it ever sees a 429.

JavaScript: a lookup with retries
This function retries 429 and 503 after Retry-After, retries 500, 502 and 504 with back-off, and throws on everything else. It returns the body on 200, so the caller decides what to do with ok, gone and unavailable. Node.js 18 or later has fetch built in.
const API = "https://api.profilehunt.dev/v1/profile";
const WAIT_FOR_HEADER = new Set([429, 503]);
const BACK_OFF = new Set([500, 502, 504]);
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
export async function lookup(url, maxAttempts = 5) {
for (let attempt = 1; ; attempt++) {
const res = await fetch(API, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.PROFILEHUNT_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url }),
});
if (res.status === 200) return res.json(); // { status, profile }
const { error } = await res.json().catch(() => ({}));
const retryable = WAIT_FOR_HEADER.has(res.status) || BACK_OFF.has(res.status);
if (!retryable || attempt === maxAttempts) {
throw new Error(`ProfileHunt ${res.status} ${error ?? ""}`.trim());
}
const retryAfter = Number(res.headers.get("retry-after"));
const seconds = WAIT_FOR_HEADER.has(res.status) && retryAfter > 0
? retryAfter
: Math.min(2 ** attempt, 30) * (0.5 + Math.random() / 2);
await sleep(seconds * 1000);
}
}
The caller then branches on the body status:
const result = await lookup("https://www.linkedin.com/in/williamhgates");
if (result.status === "ok") console.log(result.profile.full_name);
else if (result.status === "gone") console.log("No public profile; mark the record.");
else console.log("Unavailable; queue it for later.");
If fetch itself throws, the network failed before any status arrived. Treat that like a 502 and retry with back-off.
Python: the same with requests
The same logic with requests. raise_for_status() raises for any 4xx or 5xx that isn't retried, so 401, 402 and 422 surface as exceptions with the status attached.
import os, random, time
import requests
API = "https://api.profilehunt.dev/v1/profile"
WAIT_FOR_HEADER = {429, 503}
BACK_OFF = {500, 502, 504}
def lookup(url, max_attempts=5):
for attempt in range(1, max_attempts + 1):
res = requests.post(
API,
headers={"Authorization": f"Bearer {os.environ['PROFILEHUNT_KEY']}"},
json={"url": url},
timeout=60,
)
if res.status_code == 200:
return res.json() # {"status": ..., "profile": ...}
retryable = res.status_code in WAIT_FOR_HEADER or res.status_code in BACK_OFF
if not retryable or attempt == max_attempts:
res.raise_for_status()
retry_after = res.headers.get("Retry-After", "")
if res.status_code in WAIT_FOR_HEADER and retry_after.isdigit():
delay = int(retry_after)
else:
delay = min(2 ** attempt, 30) * random.uniform(0.5, 1)
time.sleep(delay)
result = lookup("https://www.linkedin.com/in/williamhgates")
if result["status"] == "ok":
print(result["profile"]["full_name"])
The timeout=60 keeps a stalled connection from hanging the worker; a lookup usually takes a few seconds. A requests.exceptions.ConnectionError is a network failure, and like a thrown fetch, it can be retried with back-off.
Handling batch failed items
In a batch, the HTTP status covers the batch and each item has its own status. Creating the batch can fail with the same retry rules as single calls: 429 and 503 after Retry-After (a 503 holds nothing), 402 stops the job with nothing held, and 422 invalid_batch means urls was missing, empty, over 100 or not all strings.
Once the batch is completed, sort the items:
ok: save the profile.gone: mark the record; don't resend. See handling not found profiles.unavailableandfailed: collect and resend later, in a new batch or as single calls.failedmeans the item couldn't be read after several tries, so an immediate resend adds little. Whyunavailableneeds spacing is explained in what an unavailable profile response means.invalid_url: fix the source data. It was never queued or charged.duplicate: the same profile appeared earlier in the batch and only the first was fetched. Copy that earlier result to this row, matching on the/in/name in the URL.
In JavaScript:
const RESEND = new Set(["unavailable", "failed"]);
const resend = batch.results.filter((r) => RESEND.has(r.status)).map((r) => r.url);
In Python:
RESEND = {"unavailable", "failed"}
resend = [r["url"] for r in batch["results"] if r["status"] in RESEND]
Every item that isn't ok has its held credit refunded, so credits_used on the batch equals the number of ok items. The full create-and-poll flow is in the batch API guide.

What Most Guides Get Wrong About Retry Logic
They retry every non-2xx. Generic retry wrappers retry 4xx too. A 401 or 422 will return the same answer forever, and every retry is time your worker could have spent on a real lookup.
They use a fixed sleep for 429. Sleeping a flat 60 seconds on every 429 wastes most of a minute when Retry-After says 12. Read the header.
They stop at the HTTP status. A wrapper that returns on 200 and calls it a success will hand gone and unavailable to code that expects a profile. The retry layer handles HTTP; the caller still has to branch on status.
Myth vs Reality
| Myth | Reality |
|---|---|
| "More retries means more cost." | Every failed lookup is free. Retries cost rate limit and time, not credits. |
"Retry unavailable in the same loop as 5xx errors." | 5xx is retried in seconds. unavailable and failed are retried minutes or hours later. |
| "Retry-After is a suggestion." | It is the exact wait. Retrying sooner on a 429 just gets another 429. |
| "A 402 is a temporary error, so back off and retry." | Out of credits is true for every request that follows. Stop the job and top up. |
| "Batch items that failed were charged." | Only ok items keep a credit. failed, unavailable, gone, invalid_url and duplicate are free. |
Advanced: Retries Across Many Workers
The rate limit is per API key, not per process. Four workers sharing one key, each pacing itself to 60 a minute, will together send 240 and collect a lot of 429s. Patterns that hold up at scale (the Python workflow at scale puts several of them into one script):
- One limiter per key, shared. Put the 60-a-minute budget in a shared store (Redis, your database, or a single dispatcher) and have every worker take a token before calling.
- A circuit breaker for 402 and 401. The first worker to see either should flip a shared flag that stops all workers. Otherwise every worker discovers the same empty balance on its own.
- A retry budget. Cap total retries per run, not just per request. If more than a set share of calls are being retried, something systemic is going on, and slowing down is better than hammering.
- Use batches for retries. Resending 300
unavailableandfailedURLs as three batches costs three requests against the limit. As single calls, it costs 300. Single calls are served before batch items, so retries in batches never slow down live lookups. - Log the request ID. Every request shows on the Usage page with an ID (
req_…). When a code looks wrong, that ID and the profile URL are what support@profilehunt.dev needs.
Where ProfileHunt Fits
ProfileHunt is a LinkedIn Profile API: one public profile URL in, structured JSON out, and you pay only for profiles found. Because failed lookups are never charged, the retry logic on this page is safe to run aggressively within the rate limit; the only bill is for ok results, at $0.50 per 1,000 profiles.
The API is plain REST with standard status codes and Retry-After, so the code above works with any HTTP client. It reads the public view of a profile only: no emails or phone numbers.
Getting Started
Sign up at profilehunt.dev/login for 100 free credits with a work email. Make one call from the quickstart, drop in the lookup function above, and test it against a made-up URL to see the gone branch. Every code is listed in the errors reference. For how lookups work end to end, see what a LinkedIn profile API is.
Frequently asked questions
How do I handle a 429 error from a LinkedIn profile API?
Wait the number of seconds in the Retry-After header, then send the same request again. ProfileHunt allows 60 requests a minute per key and resets at the start of each clock minute.
Should I use exponential backoff for LinkedIn API errors?
Yes, for 500, 502 and 504. Double the wait each attempt, cap it, and add jitter. Don't use it for 429 or 503, where Retry-After gives the exact wait.
Which LinkedIn profile API errors should I not retry?
401 (bad key), 402 (out of credits), 422 (bad URL or batch) and status: "gone". Fix the cause first; repeating the request returns the same answer.
What should I do with failed items in a LinkedIn batch API?
Collect the URLs with status: "failed" or "unavailable" and send them again later in a new batch or as single calls. They were not charged.
Do retries cost extra credits on a LinkedIn profile API?
Not with ProfileHunt. Only a response with status: "ok" uses a credit, so a profile that succeeds on the third try costs one credit.


