401 Unauthorized: causes, fixes and how it differs from 403
401 means the server doesn't know who you are. Missing headers, expired tokens, wrong formats and rotated keys, and how to read the WWW-Authenticate header.
· 4 min read · By the Spot Downtime team
401 Unauthorized means the server doesn't know who you are. Either no credentials were sent, or the ones sent weren't accepted. Despite the name, it's about authentication (who you are), not authorization (what you're allowed to do). That second one is 403 Forbidden.
401 vs 403 in one table
| 401 Unauthorized | 403 Forbidden | |
|---|---|---|
| The server is saying | Who are you? | I know who you are, and the answer is no. |
| Will logging in help? | Yes | No, you need different permissions |
| Typical cause | Missing, expired or wrong token | Valid user without access, or a firewall rule |
The usual causes
No credentials sent
The request has no Authorization header or session cookie at all. Common after moving code from a browser (where cookies are sent automatically) to a script, or when a proxy strips the header. Some setups, such as Apache with PHP-FPM, drop Authorization unless you pass it on explicitly.
The token expired
Access tokens often last an hour or less. A job that works in the morning and fails in the afternoon is usually using a token it never refreshes. Check the token's expiry (for a JWT, the exp claim) and refresh before it runs out.
The wrong format
Small differences matter. Compare what the API expects with what you send:
# Bearer token
curl -i https://api.example.com/me -H "Authorization: Bearer $TOKEN"
# API key in a custom header
curl -i https://api.example.com/me -H "X-API-Key: $KEY"
# Basic auth (curl builds the header for you)
curl -i -u user:password https://example.com/adminA missing Bearer prefix, a key with a trailing newline pasted from a file, or a test key used against the live API all produce the same 401.
The key was rotated or revoked
Someone regenerated the key in the provider's dashboard, and one forgotten server still has the old one.
Read the WWW-Authenticate header
A correct 401 response includes a WWW-Authenticate header saying which scheme the server wants, and sometimes why it refused:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token", error_description="The access token expired"Monitoring a protected endpoint
Spot Downtime's API monitors can send headers such as Authorization or an API key with every check, so a 401 then means something real changed: a revoked key, or broken auth on your side.
- Seeing
403instead? Read 403 Forbidden: causes and fixes.
Keep reading
- HTTP errors · Troubleshooting500 Internal Server Error: how to find the cause and fix itA 500 hides its reason on purpose. Where to look first, the usual causes from unhandled exceptions to full disks, and the extra checks for WordPress and PHP sites.October 5, 2026 · 5 min read
- HTTP errors · Troubleshooting404 Not Found: fix broken pages, missing routes and soft 404sWhich 404s you can ignore, which ones cost you visitors and rankings, and how to fix a whole site or section that suddenly returns Not Found.October 5, 2026 · 4 min read