API Errors Explained: 400, 401, 403, 404, 429 and 500 — How to Debug Them
A 400 is your request, a 401 is your login, a 429 is your pace. Learn what the six most common API status codes really mean and the check order that finds the fault fast.
How to Debug API Errors: 400, 401, 403, 404, 429 and 500 Explained
Every developer knows the feeling: the request leaves your code, and the API replies with a bare number and a cryptic message. The number is not the enemy — it is the first clue. HTTP status codes are grouped by who owns the problem: 4xx codes mean the client (your request) needs to change something; 5xx codes mean the server failed to handle a request it should have managed. Within those groups, each of the six common codes points at a different layer: the URL, your credentials, your permissions, your request body, or your request rate. This guide explains each code in plain terms, then gives you a check order that resolves most API failures without guesswork. The six codes at a glance Code Name In one line Whose problem? 400 Bad Request The server could not understand or validate your request Yours — syntax or data 401 Unauthorized You have not proven who you are (missing/invalid credentials) Yours — authentication 403 Forbidden The server knows who you are and still refuses Yours — permissions/scope 404 Not Found No resource exists at that URL (or the API hides it) Usually yours — URL or ID 429 Too Many Requests You are sending requests too quickly Yours — pace 500 Internal Server Error The server itself failed Theirs — but your input may have triggered it 400 Bad Request — your request is malformed or invalid The server received your request but could not process it: invalid JSON, a missing required field, a value of the wrong type, or a parameter outside the allowed range. How to debug it:
- Read the response body. Well-built APIs return field-level detail, for example: { "error": "validation_failed", "details": { "email": "must be a valid email address" } }
- Validate your JSON before sending — a trailing comma or unescaped quote is enough (see Article 3). Formatting the payload in QUORVLY developer tools QUORVLY tools directory or any validator takes seconds.
- Check types: numbers sent as strings, booleans as "true", dates in the wrong format.
- Compare against the documentation field by field, including which fields are required. Common trap: Sending a correct body with the wrong Content-Type header. If the header says text/plain while the body is JSON, many servers reject or misparse it. For JSON APIs, send Content-Type: application/json. 401 Unauthorized — you have not authenticated
Despite the name, 401 is about authentication (proving identity), not permission. It means credentials are missing, expired, malformed, or revoked. Check: • Is the Authorization header present at all — and actually sent? Test in a tool where you can inspect the raw request, not just your code's intention. • Is the scheme correct? Authorization: Bearer <token> is not the same as sending the raw token. • Has the token expired? Access tokens are often short-lived by design; a request that worked an hour ago can start failing on schedule. • Is the token for the right environment? A sandbox key against the production URL (or the reverse) commonly returns 401 or 404. • If you built the credential with Base64 (Basic auth), check for truncation or the wrong variant (see Article 21). 403 Forbidden — authenticated, but not allowed The server understood and authenticated you, and still refuses. Causes include insufficient scope or role (a read-only key attempting a write), an account that lacks a feature, IP allow-listing, or a resource owned by a different account. The 401/403 distinction that saves time: 401 says "log in properly"; 403 says "you are logged in and this is still not permitted." Re-sending credentials will never fix a 403. Instead, check the token's scopes, the account's plan or role, and whether the resource belongs to the identity you are using. 404 Not Found — nothing lives at that address The obvious cause is a wrong URL or a non-existent resource ID. The less obvious causes: • Wrong base URL or version: /v1/orders vs /v2/orders, or a missing path segment. • An ID from the wrong environment or account. • Deliberate hiding: Many APIs return 404 instead of 403 for resources you may not see, so you cannot confirm they exist. If a resource "should" exist and you get 404, consider permissions before assuming deletion. • Trailing slashes and case: Some frameworks treat /orders/ and /orders, or differently cased paths, as different routes. 429 Too Many Requests — slow down You have hit a rate limit: too many requests in a window, or a quota exhausted. This is the API protecting itself, and the correct response is to reduce pace — not to retry instantly, which makes the position worse and can extend the penalty. How to respond properly: • Honour the Retry-After header if present; it tells you how long to wait. • Otherwise use exponential backoff with jitter: wait roughly 1s, then 2s, then 4s, adding a small random variation so many clients do not retry in lockstep. • Fix the cause, not just the symptom: cache responses, batch requests where the API supports it, remove polling loops that fire more often than the data changes, and check for retry code elsewhere that multiplies requests. • Track limits before you hit them — many APIs return remaining-quota headers on successful responses. // Minimal backoff sketch (adapt to your stack)
async function fetchWithBackoff(url, options, attempt = 0) { const res = await fetch(url, options); if (res.status === 429 && attempt < 4) { const retryAfter = Number(res.headers.get("Retry-After")); const waitMs = retryAfter ? retryAfter * 1000 : Math.min(1000 * 2 ** attempt, 16000) + Math.random() * 250; await new Promise(r => setTimeout(r, waitMs)); return fetchWithBackoff(url, options, attempt + 1); } return res; } 500 Internal Server Error — the server failed A 500 means the server encountered an error it did not handle. It is, by definition, not a documented part of the API's behaviour. Your moves are limited but real:
- Retry sparingly, later. A brief backoff (as for 429) is reasonable for idempotent requests such as GETs. Be careful retrying operations that create things — if the first attempt actually succeeded server-side before failing, a blind retry can create duplicates. Use idempotency keys where the API offers them.
- Check whether your input triggered it. An unusual value — a very long string, an unexpected null, a rare character — can expose a server bug. If a minimal version of the request succeeds, vary one field at a time.
- Check the provider's status page and note the exact time, request ID (many APIs return one in the body or headers), endpoint, and a redacted copy of the request. That is what support will ask for.
- Do not hammer a failing server. Repeated instant retries help nobody and may get you rate-limited on top. Other 5xx codes you may meet: 502 (a gateway received a bad response from an upstream server), 503 (service unavailable — maintenance or overload; often temporary, respect Retry-After), and 504 (gateway timeout — the upstream took too long). The universal check order When any error appears, work through this order instead of changing things at random:
- URL — base, version, path, resource ID, environment.
- Method — GET vs POST vs PUT/PATCH vs DELETE; a wrong method often returns 404 or 405.
- Headers — Content-Type, Accept, API-version headers.
- Auth — header present, scheme correct, token valid, unexpired, right environment.
- Permissions — scopes, role, ownership (especially on 403).
- Body / parameters — valid JSON, required fields, correct types and formats.
- Rate — recent volume, quotas, Retry-After (on 429).
- Server — status page, request ID, minimal reproduction (on 5xx). Change one thing at a time and retest; otherwise you will not know what fixed it. Keep a known-good request (from the documentation's example or a working tool call) to diff against the failing one — most
bugs become visible in the diff. Common mistakes • Retrying a 429 immediately, or building retry loops with no backoff and no maximum attempts. • Treating 401 and 403 as the same problem and re-checking credentials when the real issue is scope. • Debugging from code alone without ever inspecting the raw request and response, headers included. • Assuming a 500 is "not my problem" and never testing whether a specific input triggers it. • Hard-coding a token that later expires, then debugging the application instead of the credential. FAQ Why did my request work in my API testing tool but fail in code? Compare the raw requests. The usual culprits are a header the tool added automatically, a slightly different URL, or a body your code serialised differently. Should I retry a 500 automatically? For safe, idempotent requests, a small number of retries with backoff is standard. For operations that create or charge, only retry if the API supports idempotency — or first check whether the operation already succeeded. What does it mean if I get 404 for a resource I know exists? Possibly a wrong environment or account, a wrong ID format — or the API deliberately returns 404 instead of 403 to avoid revealing that the resource exists. Is 429 a ban? Usually not. It is a rate limit with a window. Respect Retry-After, reduce your request rate, and service normally resumes. Where do I find the real error detail? In the response body and headers, not the status line. Always log both (with credentials and personal data redacted) when debugging. Conclusion Status codes are a map, not a mystery: 400 points at your data, 401 at your identity, 403 at your permissions, 404 at your address, 429 at your pace, and 500 at the server. Work the check order — URL, headers, auth, body, rate, server — change one variable at a time, and let the response body speak. Debugging becomes a procedure instead of a guessing game. Sources: MDN Web Docs, HTTP response status codes, https://developer.mozilla.org/en-US/docs/Web/HTTP/Status ; RFC 9110, HTTP Semantics (status code definitions), https://www.rfc-editor.org/rfc/rfc9110 ; MDN Web Docs, HTTP authentication, https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
Related reading
- AI for Developers: Debugging, Explaining Code and Writing Tests
- How to Fix Invalid JSON: 10 Common Errors With Examples
- Base64 Explained: How Encoding Works, When to Use It and When Not To
Explore QUORVLY tools
Put this into practice with the free Quorvly tools — no account needed, nothing uploaded.
All articles