Azure OpenAI Integration is not working
Resolved 💬 15 comments Opened May 11, 2025 by adhishthite Closed Aug 7, 2025
💡 Likely answer: A maintainer (thegovind, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
0.1.2504301751
Which model were you using?
o4-mini
What platform is your computer?
Darwin 24.4.0 arm64 arm
What steps can reproduce the bug?
- Open
~/.codex/config,json - Put the config as below:
{
"provider": "azure",
"model": "o4-mini",
"providers": {
"azure": {
"name": "AzureOpenAI",
"baseURL": "https://REDACTED.openai.azure.com/openai",
"envKey": "REDACTED"
}
}
}
- Run this command to add env vars in the CLI:
export AZURE_OPENAI_API_KEY="REDACTED"
export AZURE_API_KEY="REDACTED"
- Run
codexin the CLI - See the output
What is the expected behavior?
The expected behavior is that I see the models that are hosted on the Azure Endpoint.
What do you see instead?
Instead, I see this:
❯ codex
Missing azure API key.
Set the environment variable AZURE_API_KEY and re-run this command.
You can create a AZURE_API_KEY in the azure dashboard.
Additional information
_No response_
15 Comments
@tibo-openai @thegovind Can you please check?
@adhishthite - You have to build from source. OpenAI hasn't cut a new release with the changes. And, in your
config.json(under$HOME/.codex), you can just point to an env variable. In my case that is "envKey": "AZURE_OPENAI_API_KEY", and just set this env variable before running. I just tested from main, and it's working fine with AZURE_OPENAIOh, it turns out the codex release doesn't include this update yet... That explains why I can't use Azure OpenAI on my side either... However, there might still be an issue with the environment variables. Taking the following configuration as an example:
"provider": "azure",
"model": "o4-mini",
"providers": {
"azure": {
"name": "AzureOpenAI",
"baseURL": "https://REDACTED.openai.azure.com/openai",
"envKey": "AZURE_OPENAI_API_KEY"
}
}
It seems that in the code it tries to look for AZUREOPENAI_API_KEY instead of the environment variable name defined in envKey. In other words, the code seems to use the format provider_name_API_KEY. This envKey is not effective. At least in my attempts, it prompts that AZUREOPENAI_API_KEY cannot be found.
@adhishthite @breakstring @thegovind , I tested it with published package version 0.1.2504301751 and it works. You do not have to build from source. But I can reproduce the issue what @adhishthite is facing . You have to do this change in configuration and it would work
and set export AZURE_OPENAI_API_KEY="REDACTED"
Ok, so @jk-codertech @adhishthite - I can see where the confusion is coming from. Last minute, I was debating whether to add support for our
phi-4-reasoningmodels, so I was trying to keep it broader than just Azure OpenAI. However, I forgot to change theenvKeyback to what it was in my original PR. Let me create a new PR to fix the issue.Basically, for this one:
envKeyinconfig.jsondoesn't have to be the exact key name, but the variable you set here must match the environment variable you export.i get OpenAI rejected the request with 404. no matter what i try. could you please help? my config is
works with build from source code version
!Image
is Azure meant to be absent from the provider options ? or is it just the build from source version that supports azure open ai right now ?
These providers are coming from ~/.codex/config.json. Please make sure you have Azure as a provider in config.json
@adhishthite - I’m unable to replicate this error. Could you please paste the exact error message? Also, I don’t have AZURE_API_KEY anywhere in the code - are you setting this yourself?
@jk-codertech - What exactly did you change? I don’t see any difference between your version and [what's in the readme](@adhishthite – I’m unable to replicate this error. Could you please paste the exact error message? Also, I don’t have AZURE_API_KEY anywhere in the code—are you setting this yourself?
@jk-codertech – What exactly did you change? I don’t see any difference between your version and https://github.com/openai/codex/blob/main/README.md?plain=1#L374-L403.).
There could be an issue related to the release timing, however, build from source works. So, @tibo-openai @fouad-openai please close this issue.
On my side, whether using npm to install or running from build source, Azure OpenAI cannot be used properly.
issue 1: Unable to correctly use Azure's envKey
Although I set "AZURE_API_KEY" here, in fact, I must set AZUREOPENAI_API_KEY in the .zshrc file, not AZURE_API_KEY.
!Image
!Image
issue 2: When I set the environment variable to AZUREOPENAI_API_KEY, I can run codex, but it does not work.
You can see it tries to find the model under the Azure OpenAI path.
!Image
And when I sent a simple command "help," it tried to request the wrong chat/completions path, which caused the 404 error that everyone saw.
!Image
I knew it's a bit tricky but what I did is
https://MY_RESOURCE_NAME.cognitiveservices.azure.com/openai/.!Image
@ttpss930141011 that works!!
This setup worked for me.
~/.codex/config.toml:Afterwards you have to run this in your terminal:
export AZURE_OPENAI_API_KEY="<YOUR AZURE_OPENAI_API KEY>"Then run:
codex "what is this repo about?"Codex Version: codex-cli 0.3.0
For GPT-4.1 model, use
api-version = "2025-03-01-preview"Thank you for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, feel free to let us know.