azure models not working

Resolved 💬 9 comments Opened Jun 4, 2025 by ynareshkalyan21 Closed Oct 27, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.1.2505172129

Which model were you using?

gpt-4.1

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

https://vscode.dev/github/openai/codex/blob/main/codex-cli/src/utils/model-utils.ts#L21

https://vscode.dev/github/openai/codex/blob/main/codex-cli/src/utils/config.ts#L115
is it not able to get providers data from ~/.codex/config.json. ?

nano ~/.codex/config.json

{
"model": "gpt-4.1",
"provider": "azure",
"providers": {
"openai": {
"name": "OpenAI",
"baseURL": "https://api.openai.com/v1",
"envKey": "Open AI API KEY"
},
"openrouter": {
"name": "OpenRouter",
"baseURL": "https://openrouter.ai/api/v1",
"envKey": "OPENROUTER_API_KEY"
},
"azure": {
"name": "AzureOpenAI",
"baseURL": "https://ynare-******-swedencentral.openai.azure.com",
"envKey": "3cmGTsoIUBRKNGRA0LkeI8OIeqlzgYcJzcJw1sfDRde****************",
"AZURE_BASE_URL": "https://ynare-*******-swedencentral.openai.azure.com",
"AZURE_API_KEY": "3cmGTsoIUBRKNGRA0LkeI8OIeqlzgYcJzcJw1sfD************""
},

What is the expected behavior?

it should take api_key from nano ~/.codex/config.json

providers --> azure --> envKey
( or )

providers --> azure --> AZURE_API_KEY

https://vscode.dev/github/openai/codex/blob/main/codex-cli/src/utils/config.ts#L124

What do you see instead?

---------- error log -----
Error: No API key configured for provider: azure
at z$e (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:658:4320)
at wC (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:658:4608)
at file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:669:4055
at file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:669:4293
at Nm (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:112:27792)
at L4e (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:125:13596)
at B4e (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:125:13340)
at k4e (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:125:13246)
at O4e (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:125:13122)
at RIe (file:///Users/yarramsettinaresh/.npm/_npx/5010de4b76d2184a/node_modules/@openai/codex/dist/cli.js:129:11814)

Additional information

_No response_

View original on GitHub ↗

9 Comments

mahmutdemr · 1 year ago

You should place the API key content in the “~/.zshrc” file, not in the config.json file.
The config.json file should look like this:

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

and the following line will be included in your “~/.zshrc” file

AZURE_OPENAI_API_KEY="your-api-key"
ynareshkalyan21 · 1 year ago

thanks @mahmutdemr
it working with AZURE_OPENAI_API_KEY adding to ~/.zshrc

ynareshkalyan21 · 1 year ago

now it not raising any error, but not using Azure model.
Surprising I am not able to see logs in openAI platform dashboard, but but credits use got drained https://platform.openai.com/logs

-------- I things this it RCA -----

{
"model": "gpt-4.1",
"provider": "AzureOpenAI",
"providers": {
"openai": {
"name": "OpenAI",
"baseURL": "https://api.openai.com/v1",
"envKey": "OPENAI_API_KEY"
},
"openrouter": {
"name": "OpenRouter",
"baseURL": "https://openrouter.ai/api/v1",
"envKey": "OPENROUTER_API_KEY"
},
"azure": {
"name": "AzureOpenAI",
"baseURL": "https://nbmbb.openai.azure.com/",
"envKey": "2kJHa2A0bQMFCtg1ObyGIXqASFZGLIbfIybgGp2RVgbJ2GpNpKyJQQJ99BEACYeBjFXJ3w3AAABACOGelEB"
}

"provider": "AzureOpenAI",

but in openai-client.ts#L35 and agent-loop.ts#L334 . it's checking "azure" but in the config it;s allowing "AzureOpenAI"
please check the below two line

if (config.provider?.toLowerCase() === "azure") {
return new AzureOpenAI({
apiKey: getApiKey(config.provider),
baseURL: getBaseUrl(config.provider),
apiVersion: AZURE_OPENAI_API_VERSION,
timeout: OPENAI_TIMEOUT_MS,
defaultHeaders: headers,
});
}

kingdomseed · 1 year ago

I'm having a similar issue. API is set correctly. Model endpoint and API are checked and verified as working. Codex even launches and shows the the following:

(3.12.5) jholt@localhost mythicgme2e % codex --provider azure --model gpt-4.1 "test connection"
╭──────────────────────────────────────────────────────────────╮
│ ● OpenAI Codex (research preview) v0.1.2505172129            │
╰──────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────╮
│ localhost session: fbfafb09300b4997a29cf9b76cd36d47          │
│ ↳ workdir: ~/development/mythicgme2e                         │
│ ↳ model: gpt-4.1                                             │
│ ↳ provider: azure                                            │
│ ↳ approval: suggest 

However, the /model selector shows no modals available and is only set manually by adding --model gpt-4.1 and test connection or any other text always returns the following:

    system
    ⚠️  Network error while contacting OpenAI. Please check your connection and try again.

When I test with a basic curl command I can send and receive from my enpoint with the API key in terminal but codex is having issues using it.

kingdomseed · 1 year ago
I'm having a similar issue. API is set correctly. Model endpoint and API are checked and verified as working. Codex even launches and shows the the following: `` (3.12.5) jholt@localhost mythicgme2e % codex --provider azure --model gpt-4.1 "test connection" ╭──────────────────────────────────────────────────────────────╮ │ ● OpenAI Codex (research preview) v0.1.2505172129 │ ╰──────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────╮ │ localhost session: fbfafb09300b4997a29cf9b76cd36d47 │ │ ↳ workdir: ~/development/mythicgme2e │ │ ↳ model: gpt-4.1 │ │ ↳ provider: azure │ │ ↳ approval: suggest ` However, the /model selector shows no modals available and is only set manually by adding --model gpt-4.1 and test connection or any other text always returns the following: ` system ⚠️ Network error while contacting OpenAI. Please check your connection and try again. `` When I test with a basic curl command I can send and receive from my enpoint with the API key in terminal but codex is having issues using it.

I discovered that the baseURL was not getting set by the yaml configuration but was set when using export

provider: azure                 # Use Azure OpenAI as the provider
model: gpt-4.1                  # Model name **must match your Azure deployment name**:contentReference[oaicite:0]{index=0}
providers:
  azure:
    name: AzureOpenAI
    baseURL: "https://jason-1275-resource.openai.azure.com//openai"
    envKey: AZURE_OPENAI_API_KEY

Now I've got a new error unrelated to this issue. But I think the OPs issue still stands--some how config values are not getting picked up and the env file is not loading correctly. It only works when I export to shell.

ishowshao · 1 year ago

not working too

ishowshao · 1 year ago

The configuration file is not read at all,

codex
Sign in with ChatGPT
  Paste an API key (or set as OPENAI_API_KEY)
doggy8088 · 10 months ago
etraut-openai contributor · 8 months ago

I think this issue is no longer relevant, so I'm closing it out. If you have related questions, please feel free to post to the discussion forum. Or feel free to open a new bug report.