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

View original on GitHub ↗

32 Comments

notlikejuice · 1 year ago

i have same problem, providers like openrouter or others doesnt workin

● OpenAI Codex (research preview) v0.1.2505161800            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: b555630e7ba148338c14078db0b8bea1          │
│ ↳ workdir: ~/.../OneDrive/Aplikacje/mess/mess v2             │
│ ↳ model: grok-3-beta                                         │
│ ↳ provider: xai                                              │
│ ↳ approval: suggest  
anirugu · 1 year ago

I am also stuck with same problem, can't use gemini in openai.

qtqgyt · 1 year ago
I am also stuck with same problem, can't use gemini in openai.

Yup, although for me it says error 400, instead of 401.

avenda · 1 year ago

same:

 codex --provider gemini -m gemini-2.0-flash
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2505171619            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: d3b205271ad443ce8a7f37c20498895f          │
│ ↳ workdir: ~/workspace/test-folder                           │
│ ↳ model: gemini-2.0-flash                                    │
│ ↳ provider: gemini                                           │
│ ↳ approval: suggest                                          │
╰──────────────────────────────────────────────────────────────╯
user
das

    system
    ⚠️  OpenAI rejected the request. Error details: Status: 400, Code: unknown, Type: unknown, Message: 400 status code (no body). Please verify your settings and try again.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ctrl+c to exit | "/" to see commands | enter to send — 100% context left```
uqe · 1 year ago

Same issue.

!Image

pallavbakshi · 1 year ago

Here's a solution that works for me.

Instead of setting your OPENROUTER_BASE_URL and OPENROUTER_API_KEY, set OPENAI_BASE_URL and OPENAI_API_KEY.

Example

export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
export OPENAI_API_KEY="sk-***-21"

Note: In the above example, pay attention to the actual URL, I'm using "openrouter" endpoint and NOT "openai" endpoint.

superiorlu · 1 year ago
Here's a solution that works for me. Instead of setting your OPENROUTER_BASE_URL and OPENROUTER_API_KEY, set OPENAI_BASE_URL and OPENAI_API_KEY. Example export OPENAI_BASE_URL="https://openrouter.ai/api/v1" export OPENAI_API_KEY="sk-***-21" 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:

  1. set env:
export OPENAI_BASE_URL=https://api.deepseek.com/
export OPENAI_API_KEY=sk-****15
export DEEPSEEK_API_KEY=sk-****15
  1. change model and provider:

~/.codex/config.json:

``` json

{
"model": "deepseek-chat",
"provider": "deepseek",
...
}

3. run: `codex --approval-mode full-auto "create the fanciest todo-list app"`
bkf777 · 1 year ago

!Image
I have the same problem, it seems like I have no support for function calls

anirugu · 1 year ago

@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

webpolis · 1 year ago

Same here. Gemini provider not working. A regular Curl call shows there is no problem with Google's OpenAI API:

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-03-25",
    "messages": [
        {"role": "user", "content": "Explain to me how AI works"}
    ],
    "stream": true
  }'
...
data: {"choices":[{"delta":{"content":"Okay, let's break down how Artificial Intelligence (AI) works, starting simple and then adding a","role":"assistant"},"index":0}],"created":1747711087,"model":"gemini-2.5-pro-preview-03-25","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":" bit more detail.\n\nImagine you're trying to teach a child to recognize a cat.\n\n1.  **","role":"assistant"},"index":0}],"created":1747711087,"model":"gemini-2.5-pro-preview-03-25","object":"chat.completion.chunk"}
...

Codex just fails with ambiguous 400 error:

user
provide an overview of the current project
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│(   ●  ) 1s  Thinking..                                                                                                                                        press Esc twice to interrupt │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ctrl+c to exit | "/" to see commands | enter to send — 100% context left

OpenAI:DEBUG:response (error; (error; no more retries left)) 400 https://generativelanguage.googleapis.com/v1beta/openai/chat/completions {
  'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
  'content-encoding': 'gzip',
  'content-type': 'application/json; charset=UTF-8',
  date: 'Tue, 20 May 2025 03:16:35 GMT',
  server: 'scaffolding on HTTPServer2',
  'server-timing': 'gfet4t7; dur=876',
  'transfer-encoding': 'chunked',

    system
    ⚠️  OpenAI rejected the request. Error details: Status: 400, Code: unknown, Type: unknown, Message: 400 status code (no body). Please verify your settings and try again.
overheat · 1 year ago

just rm ~/.codex/auth.json
It's works for me.

webpolis · 1 year ago

There's no auth.json here

bedorlan · 1 year ago

it worked for me like this:

export GEMINI_API_KEY="your gemini key here"
export OPENAI_API_KEY="$GEMINI_API_KEY"
export GEMINI_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
codex -p gemini -m gemini-2.5-flash-preview-05-20
BillWang-dev · 1 year ago
just rm ~/.codex/auth.json It's works for me.

thanks!!!!

BillWang-dev · 1 year ago
just rm ~/.codex/auth.json It's works for me.

when I removed the json, I use following command.

export DEEPSEEK_API_KEY="sk-XXXXXX"

export OPENAI_API_KEY="$DEEPSEEK_API_KEY"

codex -p deepseek -m deepseek-chat
anirugu · 1 year ago

I removed the auth.json and tried to write "hello world" it's end up as this error, any idea?

!Image

cc @bedorlan

bedorlan · 1 year ago
I removed the auth.json and tried to write "hello world" it's end up as this error, any idea?

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)

anirugu · 1 year ago

@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.

bedorlan · 1 year ago

@anirugu i had success using gpt-4.1-mini, that one is what works best for me cost-effective.

anirugu · 1 year ago

@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!

lazorfuzz · 1 year ago
yes, im getting that one too when using the gemini-2.5-flash model. it has been reported here: #1077

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 azure gpt-4.1-mini?

jainara-git · 1 year ago

<img width="682" alt="Image" src="https://github.com/user-attachments/assets/93e5def0-8aba-4b1d-adeb-b51e5ec6b73a" />

Facing the same issue. Kinda pathetic tbh

msmhrt · 1 year ago
luizniero · 1 year ago
just rm ~/.codex/auth.json It's works for me.

Do it inside directory that you are using codex.
Thank you,

FocusProgram · 1 year ago

It's been a problem for a long time. It's never been fixed.

wiiiimm · 1 year ago

@FocusProgram I wonder if we can just fork it and ask Copilot to fix the issue in the background 😂

mrsoo · 1 year ago
just rm ~/.codex/auth.json It's works for me.

awesome~ u save my day, my job and my life <3

okineadev · 1 year ago

My solution for this problem:

export GEMINI_API_KEY="qwertyuiop12345"
export OPENAI_API_KEY="$GEMINI_API_KEY"

codex --provider gemini

As i understand, if you don't set the OPENAI_API_KEY variable, codex simply won't start

And yes, OPENAI_API_KEY should also be the Gemini API key.

badger-99 · 1 year ago

Here is what I did to use deepseek with codex:

I made a /.codex/config.toml in the root of my project that looked like this

model = "deepseek-chat"
model_provider = "deepseek"

[model_providers.deepseek]
name     = "DeepSeek"
base_url = "https://api.deepseek.com"
env_key  = "DEEPSEEK_API_KEY"
stream = true

Then I added export CODEX_HOME="$(pwd)/.codex" to my ~/.bashrc file 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 codex will install rust-based codex that only works with .toml files and ignores .json files.

Edit: I use Ububtu 22.04.5 in wsl2 on windows so I only just learned that the ~/.codex had 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.

codex-maintainers · 11 months ago

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.

jefftan83 · 5 months ago

unexpected status 404 Not Found: Unknown error, url: https://api.deepseek.com/responses
codex deepseek

oxysoft · 2 months ago

For people still landing here from DeepSeek searches: DeepSeek V4 still exposes the OpenAI-compatible Chat Completions surface, not a native /responses endpoint, so direct https://api.deepseek.com/responses / /v1/responses fails.

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 both deepseek-v4-pro and deepseek-v4-flash.

Minimal current config shape:

[model_providers.deepseek]
name = "DeepSeek"
base_url = "http://127.0.0.1:8787/v1"
experimental_bearer_token = "codex-deepseek-local"
wire_api = "responses"

[profiles.deepseek-v4-pro]
model_provider = "deepseek"
model = "deepseek-v4-pro"
model_context_window = 1000000
approval_policy = "untrusted"
sandbox_mode = "workspace-write"

Start Codex with the profile, not just the model flag:

codex -p deepseek-v4-pro

Using codex -m deepseek-v4-pro by 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.