401 Unauthorized means the request has no valid credentials. Despite the name, it is about authentication: the server does not know who you are. It must include a WWW-Authenticate header saying how to authenticate.
HTTP/1.1 401 UnauthorizedCommon causes
- No Authorization header, or a missing API key.
- An expired or revoked token, or a JWT whose signature or audience does not match.
- Wrong username and password for basic auth.
How to fix it
- Send credentials in the scheme named by WWW-Authenticate, such as Authorization: Bearer <token>.
- Refresh the access token if it expired, then retry once.
- Decode the JWT to check its exp, aud and iss claims.