Using an alternate provider requires pasting API key every time
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
12 Comments
Having the similar issue. But not able to run codex, it crashes after all.
Also test my API key and model with
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
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 Iunset OPENAI_API_KEYand enter the Gemini one on startup, it seems to work.Does Codex accidentally send the
OPENAI_API_KEYto Google...?Cross check: I set
OPENAI_API_KEYto my Gemini key and it works out of the box!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.
In my case, the way to get rid of this error was to enter gemini baseURL and envKey into the ollama provider. 🙃
<img width="956" alt="Image" src="https://github.com/user-attachments/assets/a1b5e7ed-bc0a-4ce6-8d39-b7cabde4ffac" />
Maybe OpenAI are stretching that vibe coding thing a bit too much... 😅
My workaround for version
0.1.2505172129In ollama works
same with me. deepseek is also not work for me. DEEPSEEK_API_KEY not work, must paste everytime
!Image
for now to avoid this asking everytime you guys can doing this:
export OPENAI_API_KEY="your real provider API"SAVE MY YEAR. LOL OpenAI spend much time on vide coding that's cause of this bug =))
I had the same issue with the azure provider.
OPENAI_API_KEYhad to be defined, even though I was NOT using openai provider.Setting
OPENAI_API_KEYasenvKeyfor the azure provider did the trick.~/.codex/config.json: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.