[BUG] API Error 401 - OAuth error

Resolved 💬 16 comments Opened Mar 11, 2026 by pm0code Closed May 25, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

API Error: 401
{"type":"error","error":{"type":"authentication_error","message":"Invalid
authentication credentials"},"request_id":"req_011CYwVksiyBbVdDiMU5xzr7"} · Please run /login

What Should Happen?

OAuth process should finish and return the results

Error Messages/Logs

OAuth error: timeout of 15000ms exceeded

Steps to Reproduce

try to use Claude Code

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

Claude Code v2.1.72

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

16 Comments

xrompdev · 4 months ago

+1

github-actions[bot] · 4 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/33217
  2. https://github.com/anthropics/claude-code/issues/33214
  3. https://github.com/anthropics/claude-code/issues/33213

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

jameswangchen · 4 months ago

+1

Zeinot · 4 months ago

+1

therron-tyler · 4 months ago

+1

butnows · 4 months ago

+1

jerin081-zuper · 4 months ago

try /logout and then /login again. it worked for me

amandeavor · 4 months ago

Root Cause

Claude Code v2.1.72 appears to fail during the OAuth authentication flow. The CLI attempts to exchange the OAuth authorization code for an access token, but the request times out:

OAuth error: timeout of 15000ms exceeded

After the timeout occurs, Claude Code proceeds without a valid token, which causes the subsequent API request to fail with:

API Error: 401
Invalid authentication credentials

This indicates the OAuth token exchange step is failing or timing out, leaving the CLI in an unauthenticated state.

---

Proposed Fix

Improve the OAuth token exchange logic by:

  1. Increasing the timeout window for the token exchange request.
  2. Adding retry logic if the exchange request times out.
  3. Preventing API calls until authentication completes successfully.

---

Example Patch (TypeScript)

Increase OAuth Timeout

const OAUTH_TIMEOUT_MS = 60000; // increase from 15000ms

const response = await axios.post(
  tokenEndpoint,
  payload,
  { timeout: OAUTH_TIMEOUT_MS }
);
Add Retry Logic for Token Exchange
async function exchangeOAuthToken(code: string) {
  const MAX_RETRIES = 2;

  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
    try {
      return await requestToken(code);
    } catch (err: any) {
      if (attempt === MAX_RETRIES) throw err;

      if (err.message?.includes("timeout")) {
        await new Promise(r => setTimeout(r, 1000));
      } else {
        throw err;
      }
    }
  }
}
Prevent API Calls Without Valid Token
if (!authToken) {
  throw new Error("Authentication failed. Please run /login again.");
}
Expected Result After Fix

/login completes without timing out.

OAuth token exchange succeeds.

Claude Code stores the access token locally.

API requests no longer return 401 Invalid authentication credentials.

Impact

Fixes login failures introduced in Claude Code v2.1.72.

Prevents authentication from failing due to short network timeouts.

Improves reliability for slower networks or delayed OAuth responses.
renavides · 4 months ago

I found a workaround for this issue. I used the binary from a previous version (2.1.50), which can be found in ~/.local/share/claude/versions. I logged in using that version, and once the authentication was successful, I was able to switch back and use the latest version (2.1.72) without any problems."

pm0code · 4 months ago

this is happening again, 6:51 pm PST :(

pm0code · 4 months ago

It is happening again:
API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal
server error"},"request_id":

Why do we as customers have to go through this over and over again? This is simply a resource allocation matter. We are paying for the service already!

pm0code · 4 months ago

@claude ^

pm0code · 3 months ago

this is back again:
Please run /login · API Error: 401
{"type":"error","error":{"type":"authentication_error","message":"OAuth token has
expired. Please obtain a new token or refresh your existing
token."},"request_id":"req_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}

OAuth error: timeout of 15000ms exceeded

We are losing critical work hours for a paid service?!?

@claude ^

BrianSlatts1980 · 3 months ago

From interaction with Fin (Claude Support) the following helped me:

This 401 is most likely Claude Code picking up an API key (or an old/expired credential) instead of using your Pro OAuth token.

Try this exact sequence:
Run /logout (even if it returns 401).
Run claude update.
Fully restart your terminal (quit the terminal app, reopen).
Run claude and complete the login again.

Also double-check you have no ANTHROPIC_API_KEY anywhere in your shell profile (.zshrc/.bashrc/.profile) and run unset ANTHROPIC_API_KEY before starting Claude Code, since an API key takes precedence and can cause 401s if it’s disabled/expired.

I hope this helps others!

pm0code · 3 months ago

Thanks @BrianSlatts1980. did not work.
here we go again, Monday morning and this is back again:
API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal
server error"},"request_id":"req_00000000000000000000000"}

github-actions[bot] · 1 month ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.