HTTP 401 Unauthorized

A laptop sign-in prompt sits in front of the destination server

HTTP 401 Unauthorized means the request lacks valid authentication credentials for the target resource. It can appear when credentials are missing, expired or rejected. The response carries a WWW-Authenticate challenge that tells the client which scheme applies.

Check the target credentials

For an authenticated API, check the token’s expiry, audience and expected scheme. For a browser route, sign in normally and check whether the session applies to that host and path. A TestMyProxies custom target can return 401 when the tested route expects app credentials.

Read the challenge to identify the layer

WWW-Authenticate asks for credentials for the target resource. A proxy that challenges the client for proxy credentials uses 407 Proxy Authentication Required and Proxy-Authenticate. When sharing a diagnostic trace, keep the status and challenge type and redact credential values.

What the authentication challenge can tell you

Suppose GET /api/invoices comes back with WWW-Authenticate: Bearer realm="billing". The API is asking for a bearer token for that resource. Check the account and authentication flow documented for that host. When the challenge is present after a successful CONNECT, the HTTPS tunnel is already established. A browser might show a login page or a prompt depending on the application and authentication scheme.

Trace a 401 that appears on just one route

Compare the requested hostname and path as well as the final destination when the request redirects. A browser can have a valid session cookie in one profile and an expired session in another. An API client may also withhold authentication on a redirect to a different host. For an API you own, use a request ID to check whether the authentication layer saw the expected scheme and why it rejected the request. Keep token and cookie values out of shared logs. If the service recognizes the user and refuses access to a particular resource, it can respond with 403 Forbidden.

RFC 9110.

All HTTP status codes · All proxy testing guides · Open the proxy tester