Skip to content Use Monity from Claude, ChatGPT or Codex: set up monitors and ask what changed, from a chat. Use Monity from Claude, ChatGPT or Codex Connect yours
Tutorial 3 min read

HTTP 401 Unauthorized: read WWW-Authenticate, then fix the credentials

A 401 Unauthorized means the request’s credentials are missing or were refused. How to read the WWW-Authenticate header, find where an Authorization header gets lost, tell why a token that looks right fails, and remove a leftover password prompt.

Alex Lead Product Designer
UpdatedNovember 23, 2026 Read time3 min AudienceSite owners and developers

A 401 Unauthorized means the request didn’t carry credentials the server accepts: none were sent, or the ones sent were refused. Despite the name, it’s about who you are, not what you may do; a refusal by permission is a 403. The response must say how to authenticate in a WWW-Authenticate header, and that header is the first thing to read.

Read the WWW-Authenticate header first

RFC 9110 requires a 401 to carry at least one challenge, such as Basic or Bearer. Token APIs often add the reason. This is the example from RFC 6750, the OAuth bearer token standard:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="example",
                  error="invalid_token",
                  error_description="The access token expired"
  • invalid_token: expired, revoked or malformed. Refresh it or get a new one.
  • No error at all: the server got no credentials. Look at whether your header arrives (next section).
  • Basic realm="…": the server wants a username and password, and a browser shows its own password box for it (MDN).

RFC 6750 draws the lines between codes: a malformed request is 400, a bad token 401, and a good token without enough scope 403.

Is the Authorization header even arriving?

Send the request by hand, with the header you think your code sends:

curl -i -H "Authorization: Bearer $TOKEN" https://api.example.com/me

If that works and your app doesn’t, the header is lost on the way. Three common places:

  • A redirect to another host. RFC 9110 tells clients to consider dropping Authorization and cookies when they follow a redirect, and curl sends credentials only to the first host unless you add --location-trusted. An API that moved to a new hostname, with a redirect from the old one, starts answering 401 this way.
  • PHP behind Apache. Run as CGI or FastCGI, PHP doesn’t see Authorization unless CGIPassAuth On is set (Apache docs).
  • A typo or a missing variable: the header name misspelt, or $TOKEN empty in that environment.

Tokens that look right but fail

  • The wrong scheme. Token abc where the server expects Bearer abc, or the reverse.
  • Basic credentials not encoded. Basic sends user:password in base64: echo -n 'user:password' | base64.
  • The wrong environment. A test key against the live API, or a key someone rotated.
  • A server clock that’s off. A fresh JWT can look expired, or not yet valid, to a server whose clock has drifted. RFC 7519 allows only “a few minutes” of leeway, so sync clocks with NTP.

A password box on a page that should be public

That grey browser prompt means the server answered 401 with a Basic challenge. On a public site it’s usually HTTP Basic authentication left over from staging: a .htpasswd rule or nginx auth_basic still active after launch, or set on the whole server instead of one folder. Visitors should tell the owner rather than guess passwords; owners should remove the rule from public paths.

Checking that an endpoint still demands a key

A 401 can be the right answer. An admin route or a private API that answers 200 to a request with no key is a leak. A website monitor in Monity’s uptime monitoring can treat 401 as the good status for such a route, so you’re alerted if it ever starts answering without credentials. For the opposite, a monitor can send your own header, such as an API key, and alert when the endpoint stops accepting it.

The request options of a Monity website monitor: method GET, a header Accept: application/vnd.github+json, Add a header, Follow redirects on, Accept an invalid certificate off
A website monitor’s request options: the method, your own headers (an API key goes here) and whether to follow redirects. The good status codes, 401 included, are set beside them.

More: 403 Forbidden, 400 Bad Request and all HTTP status codes.

FAQ

Questions people ask

What’s the difference between 401 Unauthorized and 403 Forbidden?

A 401 means the server doesn’t accept who you are: credentials are missing or invalid, and valid ones would work. A 403 means it refuses anyway, so signing in again with the same account won’t help.

Why do I get a 401 with a valid API key?

Usually the key isn’t arriving as the server expects: a different header name, the wrong scheme (Bearer or Token), or a redirect or proxy that drops it. Then check that it’s the live key, and that nobody rotated it.

How do I fix a 401 error in the browser?

Sign out and back in, and clear the site’s cookies if a stale session is the problem. If a browser password box appears on a page that should be public, only the site’s owner can fix it.

Does a 401 have to include WWW-Authenticate?

Yes. RFC 9110 says a server sending 401 must include at least one challenge. A 401 without it bends the standard; if there’s no way to authenticate, 403 fits better.

Can an expired token cause a 401?

Yes, it’s the most common cause in APIs. RFC 6750 answers an expired, revoked or malformed token with 401 and error="invalid_token". Refresh the token and retry.

Written by

Alex

Alex leads product design at Monity. From the plain-English setup to the way an alert is laid out, her work is about making website monitoring something anyone can use, technical or not. She writes here about product design and usability.

More by author
Kamil, Alex and Martyna A person replies within two working days

Have a question?

Pricing, security or scoping: pick one and your message goes to a person on the team.