Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

401 vs 403 vs 404: Choose the Right API Response

401 challenges missing or invalid authentication; 403 refuses a request the server understands; 404 means no current representation or a deliberately concealed resource. Learn the decision rule and avoid common API response mistakes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use 401 Unauthorized when valid authentication credentials for the requested resource are missing or invalid; include a WWW-Authenticate challenge. Use 403 Forbidden when the server understands the request but refuses it, including because the requester lacks permission. Use 404 Not Found when no current representation exists—or when policy deliberately hides that a forbidden resource exists.

How 401, 403, and 404 differ

These codes describe different outcomes from the server’s perspective. The distinction is not simply “logged out,” “not allowed,” and “missing”: 401 is tied to authentication, 403 is a refusal, and 404 concerns whether a representation is found or disclosed. These semantics are specified in RFC 9110, HTTP Semantics, published by the IETF in June 2022.

As an Amazon Associate I earn from qualifying purchases.

Status Authentication and authorization Resource and disclosure Practical meaning
401 Unauthorized Valid authentication credentials for the target resource are absent or lacking. Does not itself say whether the resource exists. The request was not applied because the client needs applicable authentication credentials. The response must include a WWW-Authenticate challenge.
403 Forbidden The server refuses the request; supplied credentials may be valid but insufficient, or the refusal may have another cause. Does not itself say whether the resource exists. The server understood the request but will not fulfill it. Retrying with the same credentials is not a useful default.
404 Not Found Does not establish whether the requester is authenticated or authorized. No current representation was found, or the server is deliberately concealing a forbidden resource’s existence. The client cannot infer from 404 alone whether the resource never existed, is temporarily unavailable, or is being hidden.

Which response should an API return?

Choose the status from the condition the server has determined, rather than using one code as a generic error. In particular, decide authentication first, then authorization, then whether the resource is present and whether revealing it is acceptable.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Credentials absent, invalid, or incomplete for the authentication scheme: return 401 and include an applicable WWW-Authenticate challenge.
  2. The request is understood, but policy denies the operation: return 403. This includes cases where the user is authenticated but lacks the necessary permission.
  3. There is no current representation for the target: return 404.
  4. The resource is forbidden and its existence should not be disclosed: a deliberate 404 response is permitted. Apply this as a consistent information-disclosure policy, not as a replacement for access checks.
  5. The server knows the resource is likely permanently gone: prefer 410 Gone over 404.

Common status-code mistakes

Returning 403 when the client needs to authenticate

If the server is asking the client to provide or correct authentication credentials, use 401. A 403 communicates refusal; it does not mean simply that the client is unauthenticated.

Sending 401 without a challenge

RFC 9110 requires a server generating 401 to send at least one WWW-Authenticate challenge applicable to the target resource. Returning 401 without that header omits a required part of the response.

Treating 403 as a universal permission error

403 means the server understood the request and refuses to fulfill it. Insufficient credentials are one possible reason, but the refusal can be unrelated to credentials. Clients should not automatically retry with the same credentials.

Assuming 404 proves permanent absence

A 404 can conceal a forbidden resource, and it does not tell the client whether the absence is temporary. When the server knows the condition is likely permanent, RFC 9110 prefers 410 Gone.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make the API error contract more informative than the status alone

A three-digit status is not always enough to explain an application failure. AWS’s Amazon S3 error-response guidance says its service-specific error code is more informative than the HTTP status and recommends using that code for handling and reporting S3 errors. That is an S3-specific contract; other APIs should document their own stable error details rather than assume the same fields or behavior.

Define the response as a unit: status, headers, and body. Amazon API Gateway documentation describes a method response as defining expected status codes, headers, and body models. Amazon Prime API error guidance uses structured error code and message fields, cautions clients against relying on undocumented response details, and notes that additional status codes may be supported in future.

  • Document which status codes each operation can return and under what conditions.
  • Document the response headers and the meaning of any machine-readable application error code and human-readable message.
  • Specify retry guidance when the service promises it; clients should not infer retry behavior from these three statuses alone.
  • Have clients rely on documented fields and handle unfamiliar status codes safely, rather than assuming the current list is exhaustive.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.