openai / openai/codex

[macOS] Codex CLI/Desktop returns 401 while the same auth.json access token is accepted via curl

Open
#41,975 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

app auth bug CLI
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

What version of the Codex App are you using (From “About Codex” dialog)?

Codex Desktop 26.825.51511; Codex CLI 0.152.0

What subscription do you have?

ChatGPT Plus

What platform is your computer?

No response

What issue are you seeing?

Codex authentication appears to succeed locally, but both Codex CLI and Codex Desktop return 401 Unauthorized when sending requests to the Codex backend.

Environment:

  • macOS
  • ChatGPT Plus
  • Codex Desktop: 26.825.51511
  • Codex CLI: 0.152.0
  • Authentication method: ChatGPT
  • Model provider: chatgpt-http
  • Auth storage mode: File
  • Auth file: ~/.codex/auth.json
  • ChatGPT web works normally

codex login status reports:

Logged in using ChatGPT

I confirmed that Codex is logged into the correct ChatGPT Plus account.

However, sending a simple prompt such as hello in Codex CLI returns:

unexpected status 401 Unauthorized: {"detail":"Unauthorized"}, url: https://chatgpt.com/backend-api/codex/responses

Codex Desktop also fails with 401 Unauthorized.

I previously also received this authentication error in Codex Desktop:

Your access token could not be refreshed because your refresh token was revoked. Please log out and sign in again.

Troubleshooting already performed

I have already tried:

  1. codex logout and signing in again.
  2. codex login --device-auth.
  3. Removing/renaming ~/.codex/auth.json and performing a fresh login.
  4. Upgrading Codex CLI from 0.144.6 to 0.152.0.
  5. Confirming that only one ChatGPT account is logged into the browser.
  6. Confirming that Codex is using the correct ChatGPT Plus account.
  7. Confirming that the following environment variables are unset:
    • CODEX_ACCESS_TOKEN
    • OPENAI_API_KEY
    • OPENAI_BASE_URL
    • CODEX_HOME
  8. Testing both Codex Desktop and Codex CLI.

codex doctor --json reports that the installation is consistent and that the auth file is ~/.codex/auth.json with auth storage mode File.

Important A/B authentication test

I tested the same endpoint manually using the access token stored in ~/.codex/auth.json.

With the Authorization header:

POST https://chatgpt.com/backend-api/codex/responses

returns:

HTTP/2 400

{"detail":"The 'None' model is not supported when using Codex with a ChatGPT account."}

This indicates that the access token from auth.json is accepted by the backend and authentication succeeds.

I repeated the same request through my macOS system proxy (127.0.0.1:7897) and received the same HTTP 400 response, so the proxy does not appear to invalidate the token.

As a control test, I sent the same request without the Authorization header. It returns:

HTTP/2 401

{"detail":"Unauthorized"}

This is the same response that Codex CLI receives.

Therefore:

  • curl + valid access token -> HTTP 400 (authentication accepted)
  • curl + no Authorization header -> HTTP 401
  • Codex CLI 0.152.0 -> HTTP 401

This suggests that Codex CLI/Desktop may not be attaching or using the valid access token from ~/.codex/auth.json, or that the authentication state/token is being replaced before the request is sent.

CLI 401 request ID:

9e109bfb-39ff-41e2-93fe-f007d9fd259c

curl request where authentication was accepted:

e8cc2b63-7083-406d-bdc7-3d9a05320bfd

What steps can reproduce the bug?
  1. Sign in to Codex using a ChatGPT Plus account.
  2. Run codex login status.
  3. Confirm that it reports Logged in using ChatGPT.
  4. Start Codex CLI with codex.
  5. Send a simple prompt such as hello.
  6. Observe that the request to https://chatgpt.com/backend-api/codex/responses returns HTTP 401 Unauthorized.
  7. Extract the access token locally from ~/.codex/auth.json and use it in a curl Authorization header against the same endpoint.
  8. Observe that the request returns HTTP 400 instead of HTTP 401, indicating that the access token itself is accepted.
What is the expected behavior?

After successfully signing in with my ChatGPT Plus account, Codex CLI and Codex Desktop should use the valid authentication credentials and be able to send requests normally.

Additional information

codex doctor --json reports:

  • Codex CLI version: 0.152.0
  • auth storage mode: File
  • auth file: ~/.codex/auth.json
  • model provider: chatgpt-http
  • installation: consistent
  • CODEX_HOME: ~/.codex

The issue affects both Codex Desktop and Codex CLI.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing authentication from codex login status and codex doctor --json through the credentials in ~/.codex/auth.json to requests sent to https://chatgpt.com/backend-api/codex/responses. Compare the CLI/Desktop request path with the curl A/B test, and consider the issue done when valid ChatGPT credentials are attached consistently and both clients no longer receive 401 responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, authentication, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.