HTTPError.net

The fastest way to diagnose, understand, and fix any HTTP status code

401 Unauthorized

Fault: Client
TL;DR

Request requires user authentication credentials.

Authentication is required and has failed or has not been provided.

What HTTP 401 Unauthorized Means

Authentication is required and has failed or has not been provided.

Request requires user authentication credentials.

Common Causes

How to Fix It (For Visitors)

How to Fix It (For Developers/Admins)

401 vs 403

401 Unauthorized means the server does not know who you are: credentials are missing, expired, or invalid. Sending valid credentials may fix it. A server sending 401 must include a WWW-Authenticate header naming the expected scheme (for example Bearer or Basic).

403 Forbidden means the server knows who you are (or does not care) and still refuses. Logging in again will not help; you need different permissions.

Checklist for API 401 Errors

Returning a 401 Unauthorized (Code Examples)

If you build APIs or web apps, here is how to send an HTTP 401 response and how to test for it:

Node.js (Express)

app.get('/resource', (req, res) => {
  res.status(401).json({ error: 'Unauthorized' });
});

Python (Flask)

@app.route('/resource')
def resource():
    return jsonify(error='Unauthorized'), 401

PHP

<?php
http_response_code(401);
header('Content-Type: application/json');
echo json_encode(['error' => 'Unauthorized']);

Check the status with curl

curl -I https://example.com/resource
# Look for: HTTP/1.1 401 Unauthorized

Frequently Asked Questions

What does HTTP 401 Unauthorized mean?

Request requires user authentication credentials. In short: Authentication is required and has failed or has not been provided.

Is 401 Unauthorized a client or server error?

401 is a 4xx client-error code, so the request itself needs to change. The server is running normally and is rejecting the request as it was sent by the browser, app, or API client.

How do I fix a 401 Unauthorized error?

Include valid Authorization header. Refresh expired tokens. Implement OAuth flow correctly.

Official Specification

The 401 Unauthorized status code is defined in RFC 9110 Section 15.5.2.

View the IANA HTTP Status Code Registry →