401 Unauthorized

HTTP 401 Unauthorized is a 4xx client error status. The request lacks valid authentication credentials. Despite the name, it means "unauthenticated".

401Status code
4xxClient error
NoCacheable by default
RFC 9110 §15.5.2Defined in

Common causes

What to do

Send credentials (for example Authorization: Bearer …). The server should include a WWW-Authenticate header.

Example response

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="api"
Content-Type: application/json

{"error":"invalid_token"}

Returning 401 in code

Express   res.status(401).json({ … });
Flask     return jsonify(…), 401
PHP       http_response_code(401);
Go        w.WriteHeader(401)
nginx     return 401;

Other 4xx codes

Frequently asked questions

What does HTTP 401 mean?
The request lacks valid authentication credentials. Despite the name, it means "unauthenticated".
Is 401 an error?
Yes. It is a client error: the request needs to change before retrying.
Does a 401 hurt SEO?
If search engines see it repeatedly on pages that should rank, those pages can be dropped from the index. Fix it quickly.