Can't use other provider model
Resolved 💬 32 comments Opened May 17, 2025 by BillWang-dev Closed Aug 7, 2025
What version of Codex is running?
0.1.2505161243
Which model were you using?
deepseek-chat
What platform is your computer?
Darwin 24.4.0 arm64 arm
What steps can reproduce the bug?
After downloading the codeX CLI, I ran codex, which prompted me to choose between logging in with ChatGPT or with an OpenAI API key.
I selected ChatGPT login, but I have no remaining credit on my ChatGPT account.
I then followed the instructions to switch the backend to DeepSeek, yet the CLI still throws an error: it continues to use the API key I created on the OpenAI API Platform instead of my DeepSeek API key.
$ cat ~/.codex/config.json
{
"model": "deepseek-chat",
"provider": "deepseek",
"providers": {
"openrouter": {
"name": "OpenRouter",
"baseURL": "https://openrouter.ai/api/v1",
"envKey": "OPENROUTER_API_KEY"
},
"gemini": {
"name": "Gemini",
"baseURL": "https://generativelanguage.googleapis.com/v1beta/openai",
"envKey": "GEMINI_API_KEY"
},
"deepseek": {
"name": "DeepSeek",
"baseURL": "https://api.deepseek.com",
"envKey": "DEEPSEEK_API_KEY"
}
},
"history": {
"maxSize": 1000,
"saveHistory": true,
"sensitivePatterns": []
}
}
$ echo $DEEPSEEK_API_KEY
sk-XXXXXXXXXXXXXXXX682d
What is the expected behavior?
_No response_
What do you see instead?
$ codex --provider deepseek --model deepseek-chat
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2505161243 │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: c01268082a6f40059f293dc9bbf2d060 │
│ ↳ workdir: ~/Desktop/JS-123456 │
│ ↳ model: deepseek-chat │
│ ↳ provider: deepseek │
│ ↳ approval: suggest │
╰──────────────────────────────────────────────────────────────╯
user
hello
system
⚠️ OpenAI rejected the request. Error details: Status: 401, Code:
invalid_request_error, Type: authentication_error, Message: 401 Authentication Fails,
Your api key: ****Tv0A is invalid. Please verify your settings and try again.
Additional information
****Tv0A is my openAI API key
32 Comments
i have same problem, providers like openrouter or others doesnt workin
I am also stuck with same problem, can't use gemini in openai.
Yup, although for me it says error 400, instead of 401.
same:
Same issue.
!Image
Here's a solution that works for me.
Instead of setting your
OPENROUTER_BASE_URLandOPENROUTER_API_KEY, setOPENAI_BASE_URLandOPENAI_API_KEY.Example
Note: In the above example, pay attention to the actual URL, I'm using "openrouter" endpoint and NOT "openai" endpoint.
this work for me:
Currently, if you want to use
DeepSeek, you can configure it as follows:~/.codex/config.json:``` json
{
"model": "deepseek-chat",
"provider": "deepseek",
...
}
!Image
I have the same problem, it seems like I have no support for function calls
@pallavbakshi Thanks for the trick, can you check if you can use this for gemini. I tried to use the url mention in repo as openai which end up as 404, I tried some other way, still not working
Same here. Gemini provider not working. A regular Curl call shows there is no problem with Google's OpenAI API:
Codex just fails with ambiguous 400 error:
just
rm ~/.codex/auth.jsonIt's works for me.
There's no auth.json here
it worked for me like this:
thanks!!!!
when I removed the json, I use following command.
I removed the auth.json and tried to write "hello world" it's end up as this error, any idea?
!Image
cc @bedorlan
yes, im getting that one too when using the gemini-2.5-flash model.
it has been reported here: https://github.com/openai/codex/issues/1077
im just using the gemini-2.5-pro for now.
(the flash model is not good atm anyway 🙈, at least for what i need)
@bedorlan Just to confirm, Gemini 2.5 Pro is not available on the free tier. Google discontinued the pro-exp-03-xx model a few weeks ago. I’ll try using Azure OpenAI instead — I noticed a positive case mentioned in this comment.
@anirugu i had success using
gpt-4.1-mini, that one is what works best for me cost-effective.@bedorlan I can confirm that Azure OpenAI is working well for me. It took significantly less effort to get it running compared to Google Gemini. Thanks!
I have a fix for it here: https://github.com/openai/codex/pull/1079
But I'm actually encountering the error with azure
o3. Are you guys not seeing the error with azuregpt-4.1-mini?<img width="682" alt="Image" src="https://github.com/user-attachments/assets/93e5def0-8aba-4b1d-adeb-b51e5ec6b73a" />
Facing the same issue. Kinda pathetic tbh
You might find this branch helpful: https://github.com/msmhrt/codex/tree/workaround/gemini-bugfix
Do it inside directory that you are using codex.
Thank you,
It's been a problem for a long time. It's never been fixed.
@FocusProgram I wonder if we can just fork it and ask Copilot to fix the issue in the background 😂
awesome~ u save my day, my job and my life <3
My solution for this problem:
As i understand, if you don't set the
OPENAI_API_KEYvariable,codexsimply won't startAnd yes,
OPENAI_API_KEYshould also be the Gemini API key.Here is what I did to use deepseek with codex:
I made a
/.codex/config.tomlin the root of my project that looked like thisThen I added
export CODEX_HOME="$(pwd)/.codex"to my~/.bashrcfile so that codex will know exactly where to find the config file. I also exported my deepseek key from the .bashrc file, but I think that is optional if you prefer to export it each time you want to run codex, and that was it. All I have to do in the future is just add the config.toml file and codex should run smoothly.For additional context,
brew install codexwill install rust-based codex that only works with.tomlfiles and ignores.jsonfiles.Edit: I use Ububtu 22.04.5 in wsl2 on windows so I only just learned that the
~/.codexhad been in the user root (not sure if that's how it's called) in wsl all along. I just didn't see it because I did not ls with the -a flag, which I also just learned about, so I ended up thinking I had to create it manually in the project's root. I'm still learning the ropes so my apologies to all the more experienced people that may have gotten confused reading my comment.Thank you for the feedback! Please try again with the latest version of Codex CLI. If the issue persists, we would appreciate a report on the
codex-rs/implementation. You can find more details about the project update here: https://github.com/openai/codex/discussions/1174.unexpected status 404 Not Found: Unknown error, url: https://api.deepseek.com/responses
codex deepseek
For people still landing here from DeepSeek searches: DeepSeek V4 still exposes the OpenAI-compatible Chat Completions surface, not a native
/responsesendpoint, so directhttps://api.deepseek.com/responses//v1/responsesfails.We published the local shim we are using to run DeepSeek V4 from current Codex:
https://github.com/holo-q/deepseek-responses-proxy
It gives Codex a local Responses endpoint and forwards to DeepSeek
/chat/completions. Tested with Codex 0.128.0 using bothdeepseek-v4-proanddeepseek-v4-flash.Minimal current config shape:
Start Codex with the profile, not just the model flag:
Using
codex -m deepseek-v4-proby itself leaves the provider on the default OpenAI/ChatGPT account path, which causes the misleading “model is not supported when using Codex with a ChatGPT account” error.