The request requires user authentication. The client must authenticate itself to get the requested response.
The request requires user authentication. The client must authenticate itself to get the requested response. Despite the name "Unauthorized," this status code is actually about authentication, not authorization. It means the server does not know who you are. You need to provide valid credentials (such as a username/password, API key, or token) before the server will process your request.
A 401 error occurs when you attempt to access a protected resource without providing valid authentication credentials. This is extremely common in API development, where every request must include a token or API key. It also happens when logging into websites with incorrect credentials, or when a session or token has expired.
The server typically responds with a WWW-Authenticate header indicating the authentication scheme expected (e.g., Basic, Bearer, Digest).
Platform-Specific Notes:
Nginx Returns 401 when auth_basic or auth_request modules reject the credentials. Check your auth configuration block.
Apache Triggers 401 with mod_auth_basic or mod_auth_digest when credentials fail validation against .htpasswd.
Cloudflare May return 401 when Access policies require authentication, or when API tokens used with Cloudflare API are invalid.
Node.js Express middleware like Passport.js or custom JWT verification returns 401 when token validation fails.
exp claim, or check session expiry timeBearer <token>, Basic <base64>, etc.credentials: 'include' in fetch and Access-Control-Allow-Credentials: true on server# Request without authentication GET /api/user/profile HTTP/1.1 Host: api.example.com # Missing: Authorization header # Server Response HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="api" Content-Type: application/json { "error": "Unauthorized", "message": "Authentication token is required", "statusCode": 401 } # Correct request with Bearer token GET /api/user/profile HTTP/1.1 Host: api.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
Authorization: Bearer <your-jwt-token> for JWT/OAuth tokens, Authorization: Basic <base64-encoded-credentials> for Basic authentication, or passing an API key via a custom header like X-API-Key: <your-key>. Make sure the token hasn't expired, the API key is active, and you're using the correct authentication scheme that the API expects.Get alerted when your authentication endpoints fail or return unexpected 401 errors. Monitor 24/7 with instant notifications.
Start Free Monitoring