HTTP 401 Unauthorized
Status code 401 · Class 4xx
Unauthorized
Also searched as: error 401, HTTP 401, 401 unauthorized, 401 error
What it means
401 Unauthorized means the server needs you to authenticate and either no credentials were sent or the ones sent are invalid or expired. Browsers may show a login prompt; APIs return it when the token or API key is missing or wrong.
Applies to: All browsers, REST APIs, nginx, Apache, IIS
How to fix HTTP 401 Unauthorized
- Log out and log back in to the site, then reload
- Clear cookies for the site so a stale session is dropped
- Check the URL; a link may point to a protected area you are not signed in to
- API clients: confirm the 'Authorization' header is actually sent (inspect it in DevTools Network or with 'curl -v')
- API clients: refresh or regenerate expired tokens and API keys and check clock drift if JWTs are rejected
- Read the 'WWW-Authenticate' response header; it states the expected scheme (Basic, Bearer, Digest)
- If you own the site: check that reverse proxies forward the Authorization header to the backend and that CORS preflight requests are not themselves being authenticated
Why it happens
RFC 9110 defines 401 as missing or invalid authentication credentials for the target resource. Expired sessions, dropped headers, wrong keys and clock skew on token validation cause most cases.
FAQ
What is the difference between 401 and 403?
401 means 'we don't know who you are, please authenticate'. 403 means 'we know who you are and you are not allowed'.
Why do I get 401 with a correct API key?
The header may not be reaching the server (stripped by a proxy or redirect), or the key is for another environment or has wrong scopes.
Related errors
Source: IANA HTTP Status Code Registry · fixes written and reviewed by the editors (see our editorial policy)
Last updated: