codex icon indicating copy to clipboard operation
codex copied to clipboard

Azure OpenAI Integration is not working

Open adhishthite opened this issue 1 year ago • 15 comments

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?

  1. Open ~/.codex/config,json
  2. Put the config as below:
{
  "provider": "azure",
  "model": "o4-mini",
  "providers": {
    "azure": {
      "name": "AzureOpenAI",
      "baseURL": "https://REDACTED.openai.azure.com/openai",
      "envKey": "REDACTED"
    }
  }
}
  1. Run this command to add env vars in the CLI:
export AZURE_OPENAI_API_KEY="REDACTED"
export AZURE_API_KEY="REDACTED"
  1. Run codex in the CLI
  2. 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

adhishthite avatar May 11 '25 02:05 adhishthite

@tibo-openai @thegovind Can you please check?

adhishthite avatar May 11 '25 02:05 adhishthite

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

thegovind avatar May 11 '25 03:05 thegovind

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

Oh, 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.

breakstring avatar May 11 '25 07:05 breakstring

@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

{
  "provider": "azure",
  "model": "o4-mini",
  "providers": {
    "azure": {
      "name": "AzureOpenAI",
      "baseURL": "https://REDACTED.openai.azure.com/openai",
      "envKey": "AZURE_OPENAI_API_KEY"
    }
  }
}

and set export AZURE_OPENAI_API_KEY="REDACTED"

jk-codertech avatar May 11 '25 13:05 jk-codertech

envKey

@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

{
  "provider": "azure",
  "model": "o4-mini",
  "providers": {
    "azure": {
      "name": "AzureOpenAI",
      "baseURL": "https://REDACTED.openai.azure.com/openai",
      "envKey": "AZURE_OPENAI_API_KEY"
    }
  }
}

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-reasoning models, so I was trying to keep it broader than just Azure OpenAI. However, I forgot to change the envKey back to what it was in my original PR. Let me create a new PR to fix the issue.

Basically, for this one: envKey in config.json doesn't have to be the exact key name, but the variable you set here must match the environment variable you export.

thegovind avatar May 11 '25 14:05 thegovind

i get OpenAI rejected the request with 404. no matter what i try. could you please help? my config is

    "azure": {
      "name": "azure",
      "baseURL": "https://NAME.openai.azure.com/openai",
      "envKey": "AZURE_OPENAI_API_KEY"
    },

da1z avatar May 11 '25 17:05 da1z

i get OpenAI rejected the request with 404. no matter what i try. could you please help? my config is

    "azure": {
      "name": "azure",
      "baseURL": "https://NAME.openai.azure.com/openai",
      "envKey": "AZURE_OPENAI_API_KEY"
    },

works with build from source code version

da1z avatar May 11 '25 18:05 da1z

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 ?

btebbutt96 avatar May 12 '25 03:05 btebbutt96

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

jk-codertech avatar May 12 '25 12:05 jk-codertech

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?

  1. Open ~/.codex/config,json
  2. Put the config as below:

{ "provider": "azure", "model": "o4-mini", "providers": { "azure": { "name": "AzureOpenAI", "baseURL": "https://REDACTED.openai.azure.com/openai", "envKey": "REDACTED" } } } 3. Run this command to add env vars in the CLI:

export AZURE_OPENAI_API_KEY="REDACTED"
export AZURE_API_KEY="REDACTED"
  1. Run codex in the CLI
  2. 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

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

thegovind avatar May 12 '25 15:05 thegovind

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

breakstring avatar May 15 '25 08:05 breakstring

I knew it's a bit tricky but what I did is

  1. vim .codex/config.json to set provider as "azure" and set baseURL in providers like what docs did for me it's https://MY_RESOURCE_NAME.cognitiveservices.azure.com/openai/.
  2. vim .codex/auth.json to modify "OPENAI_API_KEY" as exactly the same as "Key" in azure model Image

ttpss930141011 avatar May 22 '25 22:05 ttpss930141011

@ttpss930141011 that works!!

sPredictorX1708 avatar Jun 18 '25 18:06 sPredictorX1708

This setup worked for me.

~/.codex/config.toml:

profile = "azure"

[model_providers.azure-ai-foundry]
name = "azure"
base_url = "https://myazureaihubsw6098155500.openai.azure.com/openai/"
env_key = "AZURE_OPENAI_API_KEY"
query_params = { api-version = "2025-04-01-preview" }
wire_api = "responses"

[profiles.azure]
model = "codex-mini"
model_provider = "azure-ai-foundry"
approval_policy = "on-failure"

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"

eitansela avatar Jul 09 '25 11:07 eitansela

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.

codex-maintainers avatar Aug 07 '25 18:08 codex-maintainers