Cause 1 of 6
No credentials were sent at all.
Attach them: Authorization: Bearer <token> for OAuth and JWT, or whatever header the API documents. Check the actual request in the Network tab or with curl -v — a header added after the request object was built does not arrive, and that is invisible from the code alone.
Cause 2 of 6
The token has expired.
Refresh it. A JWT carries an exp claim you can inspect with a local decoder such as the jwt-decode package. Do not paste production tokens into an online decoder — a token is a live credential.
Cause 3 of 6
Cookies are not being sent on a cross-origin request.
fetch omits cookies cross-origin unless you set credentials: 'include', and the server must reply with Access-Control-Allow-Credentials: true and a specific origin. The cookie itself also needs SameSite=None; Secure to travel cross-site.
Cause 4 of 6
It is Bearer followed by exactly one space and the token; Basic auth needs base64 of user:password. A trailing newline picked up from a shell variable or a file is invisible and breaks it — printf rather than echo when building it in a script.
Cause 5 of 6
The endpoint expects a different credential type.
Some APIs take an API key on one prefix and a session cookie on another, or require a tenant header alongside the token. Check the documentation for that specific route rather than the general auth page.
Cause 6 of 6
The API returns 401 where it means 403.
The status is chosen by whoever wrote the API, and plenty conflate the two. If you are certain the credential is valid, treat it as an authorisation problem instead and check scopes, roles and plan limits.