Troubleshooting guide
401 Unauthorized: causes, fixes and how it differs from 403
A 401 means the server does not know who you are. No valid credentials arrived, whether they were missing, expired, malformed or removed on the way there.
4 min read10 sectionsUpdated
On this page
What 401 means
Despite the name, 401 means unauthenticated. The server is saying: I cannot identify you, so prove who you are and try again. A correct 401 response includes a WWW-Authenticate header naming the scheme it expects.
The difference from 403 is practical. Refreshing your token can fix a 401. No new token fixes a 403 if the account simply lacks access, so the two need different handling in client code.
Common causes
- Expired access token. Short-lived JWTs expire and the client did not refresh them.
- Missing header. Code built the request without credentials, or a browser did not send cookies on a cross-site call.
- Wrong scheme.
Authorization: token abcwhere the API requiresBearer abc. - A proxy dropped the header. Some HTTP clients deliberately remove
Authorizationwhen following a redirect to another host. - Clock skew. A server whose clock is minutes off will reject tokens as not yet valid or already expired.
- Rotated signing keys where one instance still holds the old key, which produces intermittent 401s.
Diagnose it
Read the response headers first, then inspect the token itself. If you use JWTs, decode the payload and compare exp with the current time.
# Show the challenge the server sends
curl -si https://api.example.com/me -H "Authorization: Bearer $TOKEN" | grep -iE '^(HTTP|www-authenticate)'
# Decode a JWT payload (no verification, for inspection only)
echo "$TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null; echo
# Compare the clock with a trusted time source
date -u; timedatectl status | grep -i synchronizedFixes
Refresh tokens before expiry and retry once on 401, but only once, or an invalid refresh token becomes an infinite loop. Configure your proxy to pass the header: on Nginx, proxy_set_header Authorization $http_authorization;. For cross-site browser calls, send cookies explicitly and set SameSite=None; Secure. Run NTP on every host. When rotating signing keys, publish the new key to all verifiers before you start signing with it.
Catch it automatically
Intermittent 401s usually mean one bad instance or a key rotation in progress, so break the 401 rate down by host in APM. For login itself, run a multi-step synthetic check so an authentication outage reaches you before your users report it. Log the failure reason, such as expired or bad signature, and never log the token.
What is the difference between 401 and 403?
401 means the server does not know who you are. 403 means it knows and refuses. A new token can fix a 401, while a 403 needs a change in permissions.
Why does my API call work in Postman but return 401 in the browser?
Browsers apply CORS and cookie rules that Postman does not. Check that the Authorization header survives the preflight and that cross-site cookies are allowed by SameSite.
Should a client retry after a 401?
Refresh the credential and retry once. If it still fails, stop and send the user to sign in again.
Check it now, free
- Website down checker: Is it down for everyone or just me? Check any site now.
Related reading
- 503 Service Unavailable: causes and fixes: Why servers return 503 Service Unavailable, from overload and maintenance to no healthy backends, how to diagnose each cause and how to recover and prevent it.
- 408 Request Timeout: causes and how to fix it: Understand 408 Request Timeout: slow client uploads, idle keep-alive connections and proxy settings, and how it differs from a 504 Gateway Timeout.
- 504 Gateway Timeout: causes and fixes: What causes 504 Gateway Timeout errors, how timeouts stack across CDN, load balancer and Nginx, and how to find and fix the slow request.
- SSL handshake failed: causes and fixes: Why TLS handshakes fail: expired or mismatched certificates, missing intermediates, old protocols and SNI issues, with openssl commands to diagnose each cause.
- 400 Bad Request: what it means and how to fix it: Fix a 400 Bad Request error: oversized cookies, malformed URLs, invalid JSON bodies and proxy rules, with commands to find which layer rejected it.
- 422 Unprocessable Entity: how to fix it: Fix 422 Unprocessable Entity (Unprocessable Content): validation errors in APIs and forms, CSRF tokens in Rails and Laravel, and how to read the error body.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.