Black Friday: 60% off yearly plans with code BF2026, until November 30. See the deal

Troubleshooting

401 Unauthorized: what it means and how to fix it

A 401 Unauthorized means the request has no valid authentication credentials for the resource. Despite the name, it is about authentication, not permission. Sign in, or send valid credentials, and the same request can succeed.

The short answer
  • Credentials are missing, expired or wrong. The server wants you to authenticate.
  • APIs: send a valid Authorization header, usually a fresh token.
  • If you are signed in and still refused, the answer is a 403, not a 401.

What is the difference between 401 and 403?

Authentication versus authorization
401 Unauthorized403 Forbidden
CredentialsMissing or invalidValid, but not sufficient
Question answeredWho are you?You are known, but not allowed
Retrying with credentialsCan succeedDoes not help
HeaderIncludes WWW-AuthenticateTypically none

From MDN: 401 Unauthorized and MDN: 403 Forbidden.

What does the server send with a 401?

Request and response (MDN example)
GET /admin HTTP/1.1
Host: example.com

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer

The server must send a WWW-Authenticate header naming the scheme. Here it asks for a Bearer token, which the client then sends in an Authorization header.

What causes a 401 error?

Not logged in

The page needs a session and the request has none, or the session expired.

Missing or expired token

An API call has no Authorization header, or the access token lapsed and needs refreshing.

Wrong credentials or scheme

A wrong password, a revoked key, or a Bearer token sent where Basic auth is expected.

Password-protected directory

HTTP Basic authentication is set on a folder or staging site and the browser has no valid login.

Proxy or CDN strips the header

A proxy in the path drops the Authorization header before it reaches the app.

Wrong environment

A production key used against a staging service, or the reverse.

How do you fix a 401?

  1. 01

    Visitors: sign in again

    Log in, or log out and back in. Expired sessions are the most common cause.

  2. 02

    Clear site cookies

    A broken session cookie can keep a loop of 401s. Clear cookies for that site only.

  3. 03

    Browser login prompt: check the password

    A pop-up asking for username and password is HTTP authentication. Re-enter the credentials, or ask the owner.

  4. 04

    Developers: read WWW-Authenticate

    The header names the scheme the server expects, such as Bearer. Match it exactly.

  5. 05

    Refresh the token

    If the token has an expiry, request a new one and retry. Check clock drift if the token looks valid.

  6. 06

    Check the header survives

    Confirm every proxy and CDN forwards the Authorization header to your application.

What should a developer check on a failing authenticated request?

  • The Authorization header is present on the failing request, not only on the first one
  • The scheme matches the WWW-Authenticate header, for example Bearer versus Basic
  • The token has not expired and the server clock and your clock agree
  • The credentials belong to the right environment, production or staging
  • No proxy, CDN or redirect strips the header (headers can be dropped on redirects to another host)
  • The response body, which often states why the credentials were rejected

Common questions

What does 401 Unauthorized mean?

It means the request lacks valid authentication credentials for the resource. The server expects you to log in or send a valid token or password. The response includes a WWW-Authenticate header naming the scheme.

What is the difference between 401 and 403?

A 401 means you are not authenticated, so authenticating can fix it. A 403 means the server refuses you even if it knows who you are, so logging in again changes nothing. Roles and permissions cause 403s.

Why do I get 401 on an API request?

Common reasons are a missing Authorization header, an expired or revoked token, the wrong scheme, or a key for a different environment. Read the WWW-Authenticate header and the response body for the expected scheme.

Should I use 401 or 403 to block bots?

Neither for crawl control. Google says 401 and 403 should not be used to limit crawl rate. For rate limiting, 429 is meant for it. Use 401 only when authentication is genuinely required.

Why does a browser show a login pop-up for a 401?

When a 401 response carries a WWW-Authenticate header for Basic authentication, the browser asks for a username and password. This is common on staging sites and protected folders. Cancel it and the page shows the 401 content instead.

Watch your domains automatically

Aepto monitors expiry, DNS, SSL and uptime for every domain you own and alerts you when something changes. Free for 3 domains.