codex icon indicating copy to clipboard operation
codex copied to clipboard

[Windows] Sign in with ChatGPT still generates & requires an API key (Pro user) → API charges; revoking key breaks CLI

Open 4erdenko opened this issue 1 year ago • 53 comments

Summary As a ChatGPT Pro user, I expected Codex CLI to work under my Pro plan without consuming API credits. However, the “Sign in with ChatGPT” flow auto‑creates an API key for my selected API org/project. If I revoke that key to avoid API charges, the CLI fails with 401 Incorrect API key provided and then forces me to sign in again, which creates a new API key. In short, there seems to be no way to use Codex CLI without an API key being generated and billed to the API account.

Environment

  • Codex CLI: 0.19.0 (output of codex --version)
  • Install method: npm i -g @openai/codex
  • OS: Windows 11 (running in Git Bash / MINGW64; not using WSL for this repro)
  • Organization: Personal → Default project
  • Config directory: ~/.codex/ (an auth.json file appears after login)

Steps to Reproduce

  1. Ensure no OPENAI_API_KEY is set in the environment and remove any previous Codex state:

    • Delete ~/.codex/ (or at least ~/.codex/auth.json).
  2. Run codex and select “Sign in with ChatGPT”.

  3. In the browser, select my API Organization and Default project, then click Continue.

  4. Observe that an API key named “Codex CLI (auto‑generated)” is created in the API dashboard, and ~/.codex/auth.json now holds credentials (including an sk-proj-... key).

  5. Revoke that auto‑generated key in the API dashboard.

  6. Run codex again.

Actual behavior

  • The CLI shows:

    system  ⚠️ OpenAI rejected the request ...
    Error details: Status: 401, Code: invalid_api_key, Message: 401 Incorrect API key provided: sk-proj-***********...
    
  • The CLI asks me to log in again; completing login creates a new API key. I cannot run Codex CLI without having an active API key, which leads to API charges.

Expected behavior

  • As a Pro user using “Sign in with ChatGPT”, I expected a mode that does not create or require an API key and does not consume API credits, or at least a clear toggle (“use ChatGPT plan entitlements only”).
  • If I “Disconnect” Codex CLI in ChatGPT settings or revoke the key, Codex CLI should not silently recreate a billable key.

What I tried (no change)

  • Deleted ~/.codex/ and re‑logged in.
  • Ensured OPENAI_API_KEY is unset.
  • Revoked the “Codex CLI (auto‑generated)” key multiple times — CLI always re‑creates a new key after login.

Logs From the CLI run after revoking the key (redacted):

system  ⚠️ OpenAI rejected the request (request ID: req_19a4b978fff39e57e93e03f92d4c027a).
Error details: Status: 401, Code: invalid_api_key, Type: invalid_request_error,
Message: 401 Incorrect API key provided: sk-proj-***eZoA.

I can also provide ~/.codex/log/codex-tui.log with RUST_LOG=codex_core=debug,codex_tui=debug if needed.

Why I believe this is a bug/UX gap

  • The official “Sign in with ChatGPT” docs say the flow creates a key automatically and that Disconnect only removes the OAuth grant, not the key itself. This appears to leave no path to run Codex CLI under a Pro plan without a billable API key.
  • The README also instructs users migrating from API key billing to ensure OPENAI_API_KEY is unset and re‑login; however, re‑login still auto‑creates a key, so billing remains tied to API.

Request

  • Provide a “Pro/Plus entitlement” mode that does not rely on an API key (or at least a setting to not auto‑create one).
  • Alternatively, clearly document that Codex CLI currently requires an API key and will bill the API account (even for Pro users), and outline how/when this will change.
  • If a non‑API billing mode is planned, please share timelines or a beta flag we can test.
Image

4erdenko avatar Aug 08 '25 08:08 4erdenko

I believe that we are shipped with older version of CLI for windows. Tried to build codex-rs for windows, got error about "Keyboard progressive enhancement not implemented for the legacy Windows API." which is from crossterm.

Managed to build with commented lines (just to check my assumption)

execute!(
        stdout(),
        PushKeyboardEnhancementFlags(
            KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
                | KeyboardEnhancementFlags::REPORT_EVENT_TYPES
                | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
        )
    )?;

In codex-rs\tui\src\tui.rs

And it worked - managed to make some requests to GPT. But the problem is that I can't pass login stage with this built version, so only worked for me because I logged in with my npm-shipped version and then launched this built one.

M1kEk1M avatar Aug 08 '25 08:08 M1kEk1M

same issue as: https://github.com/openai/codex/issues/1953

osichin avatar Aug 08 '25 16:08 osichin

I apologize for the inconvenience, login with ChatGPT is not fully working on Windows, we're working hard on fixing it.

pakrym-oai avatar Aug 08 '25 16:08 pakrym-oai

Same problem here

jacobhallgren avatar Aug 08 '25 23:08 jacobhallgren

Very hot off the presses, but 0.20.0 in npm https://www.npmjs.com/package/@openai/codex has some key fixes for Windows:

  • https://github.com/openai/codex/pull/2019
  • https://github.com/openai/codex/pull/2035
  • https://github.com/openai/codex/pull/2042

bolinfest avatar Aug 09 '25 01:08 bolinfest

Same problem on a pro account

Image

optimikelabs avatar Aug 09 '25 01:08 optimikelabs

@bolinfest - thank you! confirm it works now.

osichin avatar Aug 09 '25 01:08 osichin

@mickahouan for good measure, can you delete %USERPROFILE%\.codex\auth.json and try again to make sure you're doing a clean auth flow on 0.20.0?

bolinfest avatar Aug 09 '25 02:08 bolinfest

Also, maybe unset model in config.toml or perhaps other things?

bolinfest avatar Aug 09 '25 02:08 bolinfest

Ok, everything works. Thanks a lot @bolinfest

optimikelabs avatar Aug 09 '25 02:08 optimikelabs

on Windows with 0.20.0 I get: login_with_chatgpt subprocess failed

angeloc-dl avatar Aug 09 '25 07:08 angeloc-dl

I'm a pro user, on windows. Using .19. I'm getting charged for API usage when I shouldn't be.

TheComplianceAide avatar Aug 09 '25 08:08 TheComplianceAide

Sign in with ChatGPT to use Codex as part of your paid plan or connect an API key for usage-based billing

  1. Sign in with ChatGPT Usage included with Plus, Pro, and Team plans
  1. Provide your own API key Pay for what you use

Press Enter to continue

login_with_chatgpt subprocess failed

jacobhallgren avatar Aug 09 '25 09:08 jacobhallgren

I'm a pro user, on windows. Using .19. I'm getting charged for API usage when I shouldn't be.

See above: 0.20.0, delete auth.json, try codex login again?

bolinfest avatar Aug 09 '25 15:08 bolinfest

Sign in with ChatGPT to use Codex as part of your paid plan or connect an API key for usage-based billing

  1. Sign in with ChatGPT Usage included with Plus, Pro, and Team plans
  1. Provide your own API key Pay for what you use

Press Enter to continue

login_with_chatgpt subprocess failed

See above: 0.20.0, delete auth.json, try codex login again?

bolinfest avatar Aug 09 '25 15:08 bolinfest

Right now it works on 0.20.0 with Windows cmd's clients. But another, old bug with WSL 2 (Ubuntu) still there. Its another case when codex cant login you via browser from WSL. I guess we can close this issue ?

4erdenko avatar Aug 09 '25 15:08 4erdenko

4erdenko, when you say it works, do you mean, you've downloaded .20, recreated signin, used codex cli and you've checked to see that you are NOT being charged for api consumption??

Randy Blasik My availability to @.***?anonymous&ep=signature>


From: 4erdenko @.> Sent: Saturday, August 9, 2025 11:22:18 AM To: openai/codex @.> Cc: Randy Blasik @.>; Comment @.> Subject: Re: [openai/codex] [Windows] Sign in with ChatGPT still generates & requires an API key (Pro user) → API charges; revoking key breaks CLI (Issue #2000)

[https://avatars.githubusercontent.com/u/93295097?s=20&v=4]4erdenko left a comment (openai/codex#2000)https://github.com/openai/codex/issues/2000#issuecomment-3171643611

Right now it works on 0.20.0 with Windows cmd's clients. But another, old bug with WSL 2 (Ubuntu) still there. Its another case when codex cant login you via browser from WSL. I guess we can close this issue ?

— Reply to this email directly, view it on GitHubhttps://github.com/openai/codex/issues/2000#issuecomment-3171643611, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BEAXINWQ2XCVRDJDTZ2ZRRL3MYG2VAVCNFSM6AAAAACDNFR43GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCNZRGY2DGNRRGE. You are receiving this because you commented.Message ID: @.***>

TheComplianceAide avatar Aug 09 '25 15:08 TheComplianceAide

4erdenko, when you say it works, do you mean, you've downloaded .20, recreated signin, used codex cli and you've checked to see that you are NOT being charged for api consumption??

Randy Blasik My availability to @.***?anonymous&ep=signature> …

Yes. At the moment, I don’t have an API key in auth.json, and I’m getting the default GPT-5 model. No money has been deducted. So yes, THAT problem is solved. The output format is terrible, but that’s unrelated to the issue.

4erdenko avatar Aug 09 '25 15:08 4erdenko

You sir, are a bit of a hero to me. Thank you for your quick response. Ill hop on and test.

Randy Blasik My availability to @.***?anonymous&ep=signature>


From: 4erdenko @.> Sent: Saturday, August 9, 2025 11:32:50 AM To: openai/codex @.> Cc: Randy Blasik @.>; Comment @.> Subject: Re: [openai/codex] [Windows] Sign in with ChatGPT still generates & requires an API key (Pro user) → API charges; revoking key breaks CLI (Issue #2000)

[https://avatars.githubusercontent.com/u/93295097?s=20&v=4]4erdenko left a comment (openai/codex#2000)https://github.com/openai/codex/issues/2000#issuecomment-3171775205

4erdenko, when you say it works, do you mean, you've downloaded .20, recreated signin, used codex cli and you've checked to see that you are NOT being charged for api consumption??

Randy Blasik My availability to @.***?anonymous&ep=signature> …

Yes. At the moment, I don’t have an API key in auth.json, and I’m getting the default GPT-5 model. No money has been deducted. So yes, THAT problem is solved. The output format is terrible, but that’s unrelated to the issue.

— Reply to this email directly, view it on GitHubhttps://github.com/openai/codex/issues/2000#issuecomment-3171775205, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BEAXINROFBPNLEREF3AXJRT3MYICFAVCNFSM6AAAAACDNFR43GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCNZRG43TKMRQGU. You are receiving this because you commented.Message ID: @.***>

TheComplianceAide avatar Aug 09 '25 15:08 TheComplianceAide

in my opinion the log out, log in feature should be improved (user experience wise). but you guys did fix the main annoying issues so good job.

Aze1338 avatar Aug 09 '25 18:08 Aze1338