Cannot use Azure as a Provider post #1324 fix

Resolved 💬 4 comments Opened Jun 23, 2025 by kingdomseed Closed Aug 7, 2025

What version of Codex is running?

v0.1.2505172129

Which model were you using?

o3

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

  1. Setup config in ~./.codex/config.json as follows:
{
  "model": "o3",
  "provider": "azure",
  "providers": {
    "azure": {
      "name": "AzureOpenAI",
      "baseURL": "https://jhd-codex-rg.openai.azure.com/openai",
      "envKey": "AZURE_OPENAI_API_KEY"
    }
  },
  "history": {
    "maxSize": 1000,
    "saveHistory": true,
    "sensitivePatterns": []
  }
}
  1. Export the api key in terminal with: export AZURE_OPENAI_API_KEY="KEY IS HERE"
  2. Run `codex --provider azure "hello"

What is the expected behavior?

Expect message to connect to Azure as the provider, send a message, and receive a response.

What do you see instead?

Instead I receive a message to sign in to ChatGPT:

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)"`

Additional information

Once I sign in to OpenAI, codex correctly uses Azure as its provider but fails with a new error and no help screen is provided as described in this merged PR: 1324

New error:

│ ● OpenAI Codex (research preview) v0.1.2505172129            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: 4a8c9bdc618845069dea764b67a6418e          │
│ ↳ workdir: ~/development/mythicgme2e                         │
│ ↳ model: o3                                                  │
│ ↳ provider: azure                                            │
│ ↳ approval: suggest                                          │
╰──────────────────────────────────────────────────────────────╯
user
hello

    system
    ⚠️  OpenAI rejected the request. Error details: Status: 401, Code: 401, Type: unknown, Message: 401 Access denied due to invalid
    subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API
    endpoint for your resource.. Please verify your settings and try again.

Happy to share more details as requested. Would be great to have azure finally working with codex.

View original on GitHub ↗

4 Comments

jehob · 1 year ago

My current fix for this is to set the "OPENAI_API_KEY" env variable too. set it to the same as AZURE_OPENAI_API_KEY. then it works at least for me, doesnt make much sense, but at least it works

kingdomseed · 1 year ago
My current fix for this is to set the "OPENAI_API_KEY" env variable too. set it to the same as AZURE_OPENAI_API_KEY. then it works at least for me, doesnt make much sense, but at least it works

I almost can't believe this works. I set this in auth.json file. Thanks for sharing the workaround.

devanshg03 · 1 year ago
My current fix for this is to set the "OPENAI_API_KEY" env variable too. set it to the same as AZURE_OPENAI_API_KEY. then it works at least for me, doesnt make much sense, but at least it works

This works, I keep getting errors after signing in with ChatGPT, as soon as I replaced the API key in auth.json it works

codex-maintainers · 1 year 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 in our project update.