Back to Status Codes
Client Error (4xx)

HTTP 401 Unauthorized

Authentication is required. The client must provide valid credentials.

401

Unauthorized

Authentication is required. The client must provide valid credentials.

What Causes HTTP 401?

  • Missing or invalid API key or token
  • Expired authentication credentials
  • Missing Authorization header
  • Invalid JWT or session token
  • Basic authentication credentials are incorrect

Code Examples

See how HTTP 401 responses look in different programming languages and tools.

curl -X GET https://api.example.com/protected
# Without auth header
# Response: 401 Unauthorized

curl -X GET https://api.example.com/protected \
  -H "Authorization: Bearer valid-token"
# Response: 200 OK

How to Fix HTTP 401

  • Provide valid authentication credentials via Authorization header
  • Check that API key or token has not expired
  • Ensure Bearer token, Basic auth, or API key format is correct
  • Redirect user to login page for web applications
  • Refresh expired tokens and retry the request

Related Status Codes

Test Your APIs

Frequently Asked Questions

What does HTTP 401 mean?

Authentication is required. The client must provide valid credentials.

What causes HTTP 401?

Missing or invalid API key or token. Expired authentication credentials. Missing Authorization header. Invalid JWT or session token. Basic authentication credentials are incorrect

How to fix HTTP 401?

Provide valid authentication credentials via Authorization header. Check that API key or token has not expired. Ensure Bearer token, Basic auth, or API key format is correct. Redirect user to login page for web applications. Refresh expired tokens and retry the request

http 401unauthorized errorhttp status codesapi error handlingrest api client error