Environment variables for custom providers are not getting picked up

Resolved 💬 9 comments Opened Apr 25, 2025 by KiBk Closed Aug 7, 2025
💡 Likely answer: A maintainer (LuciNyan, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.1.2504221401

Which model were you using?

any

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

Define variables for a custom provider with a key and baseurl
export PROXY_API_KEY="abc" && export PROXY_BASE_URL="abc" && codex --provider proxy

What is the expected behavior?

Connect to my API proxy

What do you see instead?

$ codex --provider proxy  

Missing proxy API key.

Set the environment variable PROXY_API_KEY and re-run this command.
You can create a PROXY_API_KEY in the proxy dashboard.

Additional information

It does seem like the environment variables aren't being picked up

Thank you in advance!

View original on GitHub ↗

9 Comments

crazy-treyn · 1 year ago

I am experiencing this same issue. Tried your approach of setting environment variables and using a .env file to define the api key, and I get the same error with each approach.

diegorusso · 1 year ago

I have the following:

 cat ~/.codex/config.json
{
  "model": "o4-mini",
  "provider": "openai",
  "providers": {
    "openai": {
      "name": "OpenAI",
      "baseURL": "https://openai-api-proxy.xxxx/api/providers/openai-eu/v1",
      "envKey": "OPENAI_API_KEY"
    }
  },
  "history": {
    "saveHistory": true,
    "sensitivePatterns": []
  }
}

but it gets ignored:

DEBUG=true codex --provider openai
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2504221401            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: f58632de40c045eeb916a02cab49c402          │
│ ↳ workdir: ~/work/ce-sw/repos/cpython                        │
│ ↳ model: o4-mini                                             │
│ ↳ provider: openai                                           │
│ ↳ approval: suggest                                          │
╰──────────────────────────────────────────────────────────────╯
OpenAI:DEBUG:request https://api.openai.com/v1/models { method: 'get', path: '/models' } {
  accept: 'application/json',
  'content-type': 'application/json',
  'user-agent': 'Rr/JS 4.95.1',
  'x-stainless-lang': 'js',
  'x-stainless-package-version': '4.95.1',
  'x-stainless-os': 'Linux',
  'x-stainless-arch': 'arm64',
  'x-stainless-runtime': 'node',
  'x-stainless-runtime-version': 'v22.15.0',
  authorization: 'REDACTED',
  'x-stainless-retry-count': '0',
  'x-stainless-timeout': '600'
}
OpenAI:DEBUG:response (error; (error; no more retries left)) 401 https://api.openai.com/v1/models {
...
ttchin · 1 year ago

I have tried all approaches, and nothing worked:

  1. export <provider>_API_KEY="xxxx"
  2. set envKey in ~/.codex/config.json
  3. set <provider>_API_KEY in .env
LuciNyan contributor · 1 year ago

Hi @diegorusso 👋. You can try modifying the provider's name.

// cat ~/.codex/config.json
{
  "model": "o4-mini",
  "provider": "xxxai",
  "providers": {
    "xxxai": {
      "name": "xxxAI",
      "baseURL": "https://openai-api-proxy.xxxx/api/providers/openai-eu/v1",
      "envKey": "XXXAI_API_KEY"
    }
  },
  "history": {
    "saveHistory": true,
    "sensitivePatterns": []
  }
}
ttchin · 1 year ago
I have tried all approaches, and nothing worked: 1. export _API_KEY="xxxx" 2. set envKey in ~/.codex/config.json 3. set _API_KEY in .env

okay, I know what happened now.
"envKey": "XXXAI_API_KEY" in config.json is literally "XXXAI_API_KEY", not the api key you have to replace with.

KiBk · 1 year ago

Thank you @LuciNyan, I updated to 0.1.2504251709 and your config.json worked great!

LuciNyan contributor · 1 year ago

@ttchin

jajajaja xD. I think the key is to replace "provider": "openai" with "provider": "any other AI". I suspect there’s special handling for the openai value. I haven’t had a chance to dig into the code yet, but that’s my guess. 👀

Btw, your avatar is pretty cool!!

diegorusso · 1 year ago

After upgrade to 0.1.2504251709, it picks the configuration details. I have only one provider and it is chose automatically.

codex-maintainers · 11 months ago

Thank you for the feedback! Please try again using the latest version of Codex CLI. If the issue persists, feel free to report it on the codex-rs/ implementation.