- Home
- Tools
- Developer Tools
- HTTP Status Codes
- 401 Unauthorized
401 Unauthorized
The request needs valid credentials and didn't have them: nobody is logged in, or the token is wrong or has expired.
- Class
- 4xx Client error. The request is the problem: a wrong address, missing credentials, data the server can't accept.
- Defined in
- RFC 9110
What it looks like
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="api", error="invalid_token"
What causes it
For a request to something protected, without credentials or with ones the server rejects. The response has to carry a WWW-Authenticate header that names the scheme to use, such as Basic or Bearer. With Basic, that header is what makes a browser show its login dialog.
What to do about it
Log in, or send the request again with valid credentials.
For an API: check that the Authorization header really is sent (a redirect to another host drops it), that the token has not expired, and that it belongs to this environment. A 401 that keeps coming back points at a wrong key or secret. Lacking the rights for something is a 403.
With OAuth an access token that has run out is the everyday cause. The remedy is to get a new one with the refresh token and to send the request again, which most client libraries can do by themselves.
Not to be confused with
| 403 Forbidden | The server knows who you are, or doesn't care, and still refuses. |
|---|---|
| 407 Proxy Authentication Required | The same demand, made by a proxy. |
How Google treats it
Google treats a 401 like any other 4xx: the page is not indexed, and one that was indexed is dropped. Its documentation warns against using 401 or 403 to slow the crawler down.
All codes are on the list of HTTP status codes, which can be searched by number and by word.
Other 4xx codes
- 400 Bad Request
- 402 Payment Required
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 406 Not Acceptable
- 407 Proxy Authentication Required
- 408 Request Timeout
- 409 Conflict
- 410 Gone
- 411 Length Required
- 412 Precondition Failed
- 413 Content Too Large
- 414 URI Too Long
- 415 Unsupported Media Type
- 416 Range Not Satisfiable
- 417 Expectation Failed
- 418 I'm a teapot
- 421 Misdirected Request
- 422 Unprocessable Content
- 423 Locked
- 424 Failed Dependency
- 425 Too Early
- 426 Upgrade Required
- 428 Precondition Required
- 429 Too Many Requests
- 431 Request Header Fields Too Large
- 451 Unavailable For Legal Reasons