codex - 💡(How to fix) Fix Codex silently switches to API key auth when environment variable is present, causing unintended billing [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#20099Fetched 2026-04-29 06:23:01
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4unlabeled ×2commented ×1
RAW_BUFFERClick to expand / collapse

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

Latest (Updated several times) 26.422.62136

What subscription do you have?

ChatGPT Pro

What platform is your computer?

Windows

What issue are you seeing?

When developing with the OpenAI SDK, I have an API key configured in my Windows environment variables. The Codex app intermittently switches from my ChatGPT plan to API key authentication without clear indication. This results in unintended usage of my paid API credits.

What steps can reproduce the bug?

Set an OPENAI_API_KEY in system environment variables (e.g. for SDK development) Log into Codex using a ChatGPT account with an active plan Start using Codex normally At some point (e.g. restart, session change, or tool invocation), Codex begins using the API key instead of the ChatGPT session

What is the expected behavior?

Codex should default to ChatGPT session authentication when the user is logged in OR clearly prompt the user before switching authentication modes OR provide a persistent, highly visible indicator of which billing mode is active

What is the actual behavior?

Codex silently switches to API key authentication No obvious warning or confirmation Leads to unintended API spend

Additional information

Impact:

High — causes unexpected financial cost Easy to miss during normal development flow Particularly problematic for developers who must have API keys set locally

Suggested Fixes:

Explicit auth mode toggle (ChatGPT vs API) Persistent UI indicator (e.g. “Using API key – billed per token”) Confirmation dialog before switching auth modes Option to disable API key auto-detection entirely Project-level or session-level auth locking

Environment:

Windows OpenAI SDK in use (API key required in environment variables) Codex app

Additional Context: This is especially problematic in workflows where developers are actively switching between SDK usage and Codex, as the auth mode can change without user awareness.

extent analysis

TL;DR

The Codex app should be modified to prioritize ChatGPT session authentication when a user is logged in, or provide clear indicators and prompts when switching to API key authentication to prevent unintended usage of paid API credits.

Guidance

  • Verify that the OPENAI_API_KEY environment variable is necessary for SDK development and consider removing it when not in use to prevent accidental switches.
  • Check for any existing settings or options within the Codex app that may allow for explicit authentication mode selection or API key auto-detection disabling.
  • Consider implementing a manual auth mode toggle or persistent UI indicator as suggested fixes to increase transparency and control over authentication modes.
  • Review workflows that involve switching between SDK usage and Codex to identify potential triggers for the authentication mode change and adjust accordingly.

Example

No code snippet is provided as the issue is related to the Codex app's behavior and authentication modes, rather than a specific code implementation.

Notes

The issue is specific to the Codex app on Windows with the OpenAI SDK in use, and the suggested fixes aim to address the lack of clear indicators and prompts when switching authentication modes.

Recommendation

Apply a workaround, such as manually removing the OPENAI_API_KEY environment variable when not in use or using a separate development environment for SDK development, until a more permanent fix is implemented to prioritize ChatGPT session authentication or provide clear indicators and prompts.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Codex silently switches to API key auth when environment variable is present, causing unintended billing [1 comments, 2 participants]