Using an alternate provider requires pasting API key every time

Resolved 💬 12 comments Opened Jun 1, 2025 by jondeaton Closed Oct 27, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

When I try to an alternate provider eg gemini I am prompted to sign into chatgpt or provide OPENAI_API_KEY. This is even after setting up ~/.codex/config.json to use the alternate provider by default and setting the provider's API key in the environment.

What steps can reproduce the bug?

codex --provider gemini --model gemini-2.5-pro-preview-05-06 

I see

Sign in with ChatGPT to generate an API key or paste one you already have.
[use arrows to move, enter to select]

❯ Sign in with ChatGPT
  Paste an API key (or set as OPENAI_API_KEY)

Interestingly if I select "Paste an API key" and then paste the Gemini API key it actually works and it will go ahead using the Gemini model provider. However, its problematic to be forced to paste the API key every time I start up codex.

My ~/.codex/config.json is configured to handle gemini provider correctly and even sets it as the default. This appears to be ignored.

{
  "model": "gemini-2.5-pro-preview-05-06",
  "provider": "gemini",
  "providers": {
    "gemini": {
      "name": "Gemini",
      "baseURL": "https://generativelanguage.googleapis.com/v1beta/openai",
      "envKey": "GEMINI_API_KEY"
    }
}

and I've set GEMINI_API_KEY properly in my shell environment.

What is the expected behavior?

It should just use the specified provider without asking for login or openai API key

What do you see instead?

Sign in with ChatGPT to generate an API key or paste one you already have.
[use arrows to move, enter to select]

❯ Sign in with ChatGPT
  Paste an API key (or set as OPENAI_API_KEY)

What version of Codex is running?

0.1.2505172129

Which model were you using?

trying to use gemini-2.5-pro-preview-05-06

What platform is your computer?

Linux 6.12.20-1rodete1-amd64 x86_64 unknown

View original on GitHub ↗

12 Comments

keskinonur · 1 year ago

Having the similar issue. But not able to run codex, it crashes after all.

codex --provider gemini --model gemini-2.5-pro-preview-05-06
Paste your OpenAI API key and press <Enter>:
***************************************

│ ● OpenAI Codex (research preview) v0.1.2505172129

│ localhost session: <INTENTIONALLY_REMOVED>       
│ ↳ workdir: <INTENTIONALLY_REMOVED>    
│ ↳ model: gemini-2.5-pro-preview-05-06         
│ ↳ provider: gemini                                           
│ ↳ approval: suggest                            

  try: explain this codebase to me | fix any build errors | are there any bugs in my code?

file:///<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658


Error: No API key configured for provider: gemini
    at z$e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658:4320)
    at wC (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658:4608)
    at file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:669:4055
    at file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:669:4293
    at Nm (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:112:27792)
    at L4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13596)
    at B4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13340)
    at k4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13246)
    at O4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13122)
    at RIe (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:129:11814)

Node.js v22.16.0

Also test my API key and model with

curl "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-pro-preview-05-06",
    "messages": [
        {"role": "user", "content": "Explain to me how AI works"}
    ]
}'

What version of Codex is running?
v0.1.2505172129

Which model were you using?
trying to use gemini-2.5-pro-preview-05-06

What platform is your computer?
macOS 15.5 Apple Silicon

serpent213 · 1 year ago

Same here, running 0.1.2505172129, codex -p gemini -m gemini-2.5-pro-preview-05-06, same result with above config file or without. Codex does not pick up the API key (GEMINI_API_KEY) correctly from the environment, even if set explicitly in config. If I unset OPENAI_API_KEY and enter the Gemini one on startup, it seems to work.

Does Codex accidentally send the OPENAI_API_KEY to Google...?

Cross check: I set OPENAI_API_KEY to my Gemini key and it works out of the box!

detroittommy879 · 1 year ago

Well a temporary fix might be to find out what URLs it is trying to use for the OpenAI API (if different than the normal ones) and swap it to something else that is OpenAI compatible, or just create a script to do it. Something that can translate to your provider.

keskinonur · 1 year ago

In my case, the way to get rid of this error was to enter gemini baseURL and envKey into the ollama provider. 🙃

{
  "model": "gemini-2.5-pro-preview-05-06",
  "provider": "ollama",
  "providers": {
    "ollama": {
      "name": "Ollama",
      "baseURL": "https://generativelanguage.googleapis.com/v1beta/openai",
      "envKey": "GEMINI_API_KEY"
    }
  },
  "history": {
    "maxSize": 1000,
    "saveHistory": true,
    "sensitivePatterns": []
  }
}

<img width="956" alt="Image" src="https://github.com/user-attachments/assets/a1b5e7ed-bc0a-4ce6-8d39-b7cabde4ffac" />

serpent213 · 1 year ago
In my case, the way to get rid of this error was to enter gemini baseURL and envKey into the ollama provider. 🙃

Maybe OpenAI are stretching that vibe coding thing a bit too much... 😅

yewton · 1 year ago

My workaround for version 0.1.2505172129

GEMINI_API_KEY=ANY_TEXT_IS_OK_BUT_REQUIRED OPENAI_API_KEY=THE_REAL_GEMINI_API_KEY codex --provider gemini --model gemini-2.5-pro-preview-05-06
zereight · 1 year ago

In ollama works

stivinlen · 1 year ago

same with me. deepseek is also not work for me. DEEPSEEK_API_KEY not work, must paste everytime

!Image

aldinokemal · 1 year ago

for now to avoid this asking everytime you guys can doing this:

export OPENAI_API_KEY="your real provider API"

momo-tuannguyen12 · 1 year ago
Having the similar issue. But not able to run codex, it crashes after all. `` codex --provider gemini --model gemini-2.5-pro-preview-05-06 Paste your OpenAI API key and press <Enter>: *************************************** │ ● OpenAI Codex (research preview) v0.1.2505172129 │ localhost session: <INTENTIONALLY_REMOVED> │ ↳ workdir: <INTENTIONALLY_REMOVED> │ ↳ model: gemini-2.5-pro-preview-05-06 │ ↳ provider: gemini │ ↳ approval: suggest try: explain this codebase to me | fix any build errors | are there any bugs in my code? file:///<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658 Error: No API key configured for provider: gemini at z$e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658:4320) at wC (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:658:4608) at file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:669:4055 at file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:669:4293 at Nm (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:112:27792) at L4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13596) at B4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13340) at k4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13246) at O4e (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:125:13122) at RIe (file://<INTENTIONALLY_REMOVED>/node_modules/@openai/codex/dist/cli.js:129:11814) Node.js v22.16.0 ` Also test my API key and model with ` curl "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer GEMINI_API_KEY" \ -d '{ "model": "gemini-2.5-pro-preview-05-06", "messages": [ {"role": "user", "content": "Explain to me how AI works"} ] }' `` What version of Codex is running? v0.1.2505172129 Which model were you using? trying to use gemini-2.5-pro-preview-05-06 What platform is your computer? macOS 15.5 Apple Silicon

SAVE MY YEAR. LOL OpenAI spend much time on vide coding that's cause of this bug =))

jurekkow · 1 year ago

I had the same issue with the azure provider.
OPENAI_API_KEY had to be defined, even though I was NOT using openai provider.
Setting OPENAI_API_KEY as envKey for the azure provider did the trick.

export OPENAI_API_KEY="MY-REAL-KEY"

~/.codex/config.json:

{
  "model": "gpt-4.1",
  "provider": "azure",
  "providers": {
    "azure": {
      "name": "AzureOpenAI",
      "baseURL": "https://XXX.openai.azure.com/openai",
      "envKey": "OPENAI_API_KEY"
    }
  }
}
etraut-openai contributor · 8 months ago

Codex CLI no longer requires you to paste your API key or go through the login flow if you're using a custom model provider. I'm going to close this issue out. If you have any related questions, feel free to post to the discussion forum. If you have any related bug reports or enhancement requests, please open a new issue.