Not able to connect to codex, says "Reconnecting"
Resolved 💬 8 comments Opened Jan 3, 2026 by sulavtimsina Closed Jan 6, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
codex-cli 0.77.0
What subscription do you have?
Plus
Which model were you using?
gpt-5.1-codex-max medium But issue is with any model
What platform is your computer?
Darwin 25.2.0 arm64 arm
What issue are you seeing?
This is the first time I am trying to use Codex on my laptop. When I use the Codex command and then start a session, my first prompt doesn't complete. It says "unexpected status 401 unauthorized". I logged out and logged in again using ChatGPT+ subscription (not the API key) but looks like there is some authentication error. It can't even complete my first prompt request.
What steps can reproduce the bug?
Uploaded thread: 019b8488-1e9f-7101-8812-afc239c99ac5
What is the expected behavior?
It's expected for Codex to give me a response.
Additional information
_No response_
8 Comments
Thanks for uploading the log data. It seems to indicate that Codex is trying to log in using ChatGPT but receiving an "invalid" API key error from the server backend. That hints at a bug somewhere in the Codex CLI auth code.
You mentioned that this is the first time you're using Codex on this machine. Did you previously log in using an API key? I wonder if Codex has cached both your old (invalid) API key and your newer ChatGPT token. Open the file
~/.codex/auth.jsonand let me know if you see both an API key and token information in that file. There should be only one or the other. If you see both, that might help explain the problem you're seeing.You can likely work around the problem by deleting your
auth.jsonfile and logging in again.I deleted the
auth.json, re-logged in with Chat GPT (not API key), but I still getunexpected status 401 Unauthorized:.The
auth.jsonhas bothOPEN_API_KEY(which isnull) and alsotokens.I have
OPEN_API_KEYset in my~/.zshrcfor other purpose, not to use with codex. Since I specified to login with Chat GPT, it should not try to fetch that OPEN_API_KEY from the environment.It's fine (expected) that
auth.jsonwill contain anullOPENAI_API_KEYif you've logged in with ChatGPT.And yes, the CLI will not fetch the
OPENAI_API_KEYenvironment variable. In general, it pays no attention to this key. Just to confirm that isn't the problem, could you unset that env variable within a new terminal window and launchcodex? I don't think that will fix the problem, but I just want to verify.Do you have any non-default settings in your
config.tomlfile? For example, have you defined a custom model provider?Did you recently upgrade from a free ChatGPT account to Plus?
If you have access to another computer, are you able to log in and use Codex on that machine? I'm trying to determine if this is specific to your account or to your machine or local configuration.
This is my config.toml:
```model = "gpt-5.2-codex"
model_reasoning_effort = "medium"
[projects."/Users/---/Documents/---/---/---/repo1"]
trust_level = "trusted"
[notice.model_migrations]
"gpt-5.1-codex-max" = "gpt-5.2-codex"
I ran some command to uninstall Codex but I think it did not uninstall correctly or something happened and now when I run Codex this is what I get.
<img width="1142" height="397" alt="Image" src="https://github.com/user-attachments/assets/71fbf143-91bb-4704-95d3-3e048fd8c409" />
Does this provide any hint?
Hey @sulavtimsina, from the thread you uploaded it looks you had set (intentionally or not) the
base_urlfor theOpenAImodel provider being used tohttps://api.portkey.ai/v1. I suspect this was causing the 401s, as you signed in with ChatGPT but were hitting the Portkey responses endpoint instead of the OpenAI one.The
OPENAI_BASE_URLenv variable is used for thebase_url, so can you confirm whether you might have setOPENAI_BASE_URLto that Portkey url?And to clarify, what did you do to get to the state shown in the screenshot? It seems from that screenshot that Codex is "working", but it seems to be a very old version (
v0.1.*, when latest isv0.77.*). What do you get when you runcodex --version? Is it possible you have an old alias/installation hanging around after your uninstall?@sayan-oai I had set that intentionally. I am running some terminal bench tasks, https://www.tbench.ai/ and I have a portkey api key for that.
I assumed that if I sign in my ChatGPT(and not API Key), the api keys on zshrc would be ignored.
But now I removed(commented) that api key from ~/.zshrc, and login with ChatGPT is working fine. Thank you.
My issue is resolved, but I am confused as to when I am using ChatGPT to sign why is the API key being checked on my zshrc file.
When you sign in with ChatGPT, the
OPENAI_API_KEYvalue _is_ ignored. You can confirm what auth method you are using (API key or ChatGPT) by runningcodex login status.I don't think commenting out an API key would fix the problem if you are trying to sign in with ChatGPT while still pointing
OPENAI_BASE_URLto Portkey. If it's working now, I suspect that either a) you are now correctly authing against the Portkey endpoint with an API key or b)OPENAI_BASE_URLis getting unset and "sign in with ChatGPT" is working as intended.I think that the initial issue is resolved so I'm closing this, but happy to continue debugging with you in the comments if needed.