[macOS] Codex CLI/Desktop returns 401 while the same auth.json access token is accepted via curl
Nobody has claimed this yet.
- 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:
codex logoutand signing in again.codex login --device-auth.- Removing/renaming
~/.codex/auth.jsonand performing a fresh login. - Upgrading Codex CLI from 0.144.6 to 0.152.0.
- Confirming that only one ChatGPT account is logged into the browser.
- Confirming that Codex is using the correct ChatGPT Plus account.
- Confirming that the following environment variables are unset:
CODEX_ACCESS_TOKENOPENAI_API_KEYOPENAI_BASE_URLCODEX_HOME
- 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?
- Sign in to Codex using a ChatGPT Plus account.
- Run
codex login status. - Confirm that it reports
Logged in using ChatGPT. - Start Codex CLI with
codex. - Send a simple prompt such as
hello. - Observe that the request to
https://chatgpt.com/backend-api/codex/responsesreturns HTTP 401 Unauthorized. - Extract the access token locally from
~/.codex/auth.jsonand use it in a curl Authorization header against the same endpoint. - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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