4xx Client Errors
HTTP 401 Unauthorized
Authentication is required and has either failed or not been provided.
When is 401 used?
- Missing or invalid API key
- Expired JWT token
- Login required but not provided
How to handle a 401 response
Inspect the request — URL, method, headers, credentials, and body. Retrying the same request unchanged will usually fail again; 429 is the exception, where you should wait for the Retry-After period.
Check the status code a URL returns from the command line:
curl -s -o /dev/null -w "%{http_code}\n" https://example.comHow to return 401 from your server
Node.js (Express)
res.status(401).json({ message: 'Unauthorized' });Python (Flask)
return {"message": "Unauthorized"}, 401Go (net/http)
w.WriteHeader(401)Frequently Asked Questions
What does HTTP 401 mean?
401 Unauthorized: Authentication is required and has either failed or not been provided.
Is 401 an error?
Yes. 401 is in the 4xx Client Errors class. Client errors: the request is malformed, unauthorized, or targets something that does not exist.