codex icon indicating copy to clipboard operation
codex copied to clipboard

How to use Azure provider

Open ken19980727 opened this issue 1 year ago • 13 comments

Hi everyone,

I installed Codex CLI using the following command:

npm i -g @openai/codex

The installed version is codex-cli 0.9.0.

After installation, I followed an online example that uses Azure as the provider. However, when I ran the command below, the system gave me an error:

error: unexpected argument '--provider' found

  tip: a similar argument exists: '--profile'

Usage: codex-x86_64-unknown-linux-musl --profile <CONFIG_PROFILE> [PROMPT]

For more information, try '--help'.

I noticed that the documentation mentions using --profile, but I'm not sure how to properly use it in this case.

Could someone please point out what I'm doing wrong, or provide a working example? Thanks in advance!

ken19980727 avatar Jul 24 '25 07:07 ken19980727

Hi everyone,

I installed Codex CLI using the following command:

npm i -g @openai/codex

The installed version is codex-cli 0.9.0.

After installation, I followed an online example that uses Azure as the provider. However, when I ran the command below, the system gave me an error:

error: unexpected argument '--provider' found

  tip: a similar argument exists: '--profile'

Usage: codex-x86_64-unknown-linux-musl --profile <CONFIG_PROFILE> [PROMPT]

For more information, try '--help'.

I noticed that the documentation mentions using --profile, but I'm not sure how to properly use it in this case.

Could someone please point out what I'm doing wrong, or provide a working example? Thanks in advance!

ask grok4

vitatea2023 avatar Jul 24 '25 11:07 vitatea2023

@ken19980727 The example that you found is out of date. Please see:

https://github.com/openai/codex/blob/main/codex-rs/config.md#model_providers

bolinfest avatar Jul 24 '25 18:07 bolinfest

@ken19980727 The example that you found is out of date. Please see:

https://github.com/openai/codex/blob/main/codex-rs/config.md#model_providers

Hi @bolinfest, First of all, thank you so much for your reply, I really appreciate it!

I've updated my model_providers section. Here is my ~/.codex/config.toml:

[model_providers.azure]
name = "Azure"
base_url = "https://xxxxxxx.cognitiveservices.azure.com"
env_key = "xxxxxxxxxx4jNr"
query_params = { api-version = "2025-01-01-preview" }
wire_api = "responses"

However, when I run the codex command, it still prompts me to run codex login.

Did I miss something?

ken19980727 avatar Jul 25 '25 06:07 ken19980727

Check this thread: https://github.com/openai/codex/issues/1461

This variable is not supposed to be the value of the API key but the name of the env variable that the API key is fetched from:

env_key = "xxxxxxxxxx4jNr"

jepio avatar Jul 25 '25 10:07 jepio

Check this thread: #1461

This variable is not supposed to be the value of the API key but the name of the env variable that the API key is fetched from:

env_key = "xxxxxxxxxx4jNr"

Hi @jepio, Thank you for sharing!

After updating my ~/.codex/config.toml, the file looks like this:

profile = "codex"

[model_providers.azure]
name = "Azure"
base_url = "https://xxxxx.cognitiveservices.azure.com"
env_key = "AZURE_OPENAI_API_KEY"
params = { api-version = "2025-01-01-preview" }
wire_api = "responses"

[profiles.o4]
model = "o4-mini"
model_provider = "azure"

Then I ran:

codex

But it returned the following error:

Error loading configuration: config profile `codex` not found

It seems like it's unable to locate the codex profile.

Did I misconfigure something? I would really appreciate any guidance. Thank you!

ken19980727 avatar Jul 28 '25 03:07 ken19980727

You defined a profile called "o4" but set the default profile name to "codex" - make those two match and it'll work. (an LLM could have helped with this problem 😄)

jepio avatar Jul 28 '25 05:07 jepio

Hello! I have a very similar problem, I cannot make the azure model work. This is what my "config.toml" looks like:

model_provider = "azure"
model = "gpt-4o"

[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://xxxxxxxxxxx.cognitiveservices.azure.com/"
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = { api-version = "2024-10-21" }
# wire_api = "responses"

However when I run "codex", this is what I see:

Image

I also tried setting a profile with o4-mini and o3, or to uncomment wire_api, but the error stayed the same. I know for a fact that the service exists, because I use it for other applications too. Can you please help?

martrdev avatar Jul 28 '25 13:07 martrdev

Hello! I have a very similar problem, I cannot make the azure model work. This is what my "config.toml" looks like:

model_provider = "azure"
model = "gpt-4o"

[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://xxxxxxxxxxx.cognitiveservices.azure.com/"
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = { api-version = "2024-10-21" }
# wire_api = "responses"

However when I run "codex", this is what I see:

Image I also tried setting a profile with o4-mini and o3, or to uncomment wire_api, but the error stayed the same. I know for a fact that the service exists, because I use it for other applications too. Can you please help?

You have two options: wire_api=chat:

  • base_url must contain deployment name (model name is ignored): https://xxxxxxxxxxx.cognitiveservices.azure.com/openai/deployments/gpt-4.1

wire_api=responses:

  • base_url must end in /openai: https://xxxxxxxxxxx.cognitiveservices.azure.com/openai
  • api-version should be 2025-04-01-preview or newer
  • model name must match deployment name

Try:

model_provider = "azure"
model = "gpt-4o"


[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://xxxxxxxxxxx.cognitiveservices.azure.com/openai"
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = { api-version = "2025-04-01-preview"}
wire_api = "responses"

jepio avatar Jul 28 '25 14:07 jepio

Fantastic, I can confirm that setting the api-version to 2025-04-01-preview worked. To clarify, I already tried in the past to add "/openai" at the end of the base_url but nothing changed so that was not the (sole) reason. However, having this setting you proposed, worked 🎉

I suggest you guys add the example of the Azure endpoint being base_url = "https://YOUR_PROJECT_NAME.cognitiveservices.azure.com/openai" aside to the current example base_url = "https://YOUR_PROJECT_NAME.openai.azure.com/openai" and make sure to highlight that the api-version needs to be set up as 2025-04-01-preview or newer. I personally believe this will help.

My current config.toml file is as follows:

model_provider = "azure"
model = "gpt-4o"

[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://XXXXXXXXXX.cognitiveservices.azure.com/openai" 
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = {api-version = "2025-04-01-preview"}
wire_api = "responses"

Thanks!

martrdev avatar Jul 28 '25 14:07 martrdev

In case any else finds this.. this doesn't work if your company uses a special proxy for azure. You need to do this, which isn't well documented:

model_provider = "azure"
model = "o3"

[model_providers.azure]
name = "Azure"
base_url = "https://xxxxxxxxx.xxxx.com/openai/deployments/o3"
query_params = { api-version = "2025-04-01-preview" }
wire_api = "chat"
# Use env_http_headers to set the api-key header (Azure doesn't use Bearer auth)
env_http_headers = { api-key = "AZURE_OPENAI_API_KEY" }

[profiles.o3]
model = "o3"
model_provider = "azure"

abazabaaa avatar Jul 29 '25 00:07 abazabaaa

Hello! I have a very similar problem, I cannot make the azure model work. This is what my "config.toml" looks like:

model_provider = "azure"
model = "gpt-4o"

[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://xxxxxxxxxxx.cognitiveservices.azure.com/"
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = { api-version = "2024-10-21" }
# wire_api = "responses"

However when I run "codex", this is what I see: Image I also tried setting a profile with o4-mini and o3, or to uncomment wire_api, but the error stayed the same. I know for a fact that the service exists, because I use it for other applications too. Can you please help?

You have two options: wire_api=chat:

  • base_url must contain deployment name (model name is ignored): https://xxxxxxxxxxx.cognitiveservices.azure.com/openai/deployments/gpt-4.1

wire_api=responses:

  • base_url must end in /openai: https://xxxxxxxxxxx.cognitiveservices.azure.com/openai
  • api-version should be 2025-04-01-preview or newer
  • model name must match deployment name

Try:

model_provider = "azure"
model = "gpt-4o"


[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://xxxxxxxxxxx.cognitiveservices.azure.com/openai"
env_key = "AZURE_OPENAI_API_KEY"
# Newer versions appear to support the responses API, see https://github.com/openai/codex/pull/1321
query_params = { api-version = "2025-04-01-preview"}
wire_api = "responses"

Hi @jepio , thanks again for your guidance!

I’ve updated my config.toml as follows:

model_provider = "azure"
model = "gpt-4.1-mini"

[model_providers.azure]
name = "Azure"
base_url = "https://xxxx.openai.azure.com/openai/deployments/gpt-4.1-mini"
env_key = "AZURE_OPENAI_API_KEY"
params = { api-version = "2025-01-01-preview" }
wire_api = "chat"

As you can see, I’ve switched the model_provider to azure, and pointed the base URL to the correct deployment endpoint.

However, the response still shows a 404 Not Found error.

Image

Could you help me identify what might be going wrong?

Thanks in advance!

ken19980727 avatar Jul 30 '25 02:07 ken19980727

I’ve updated my config.toml as follows:

model_provider = "azure"
model = "gpt-4.1-mini"

[model_providers.azure]
name = "Azure"
base_url = "https://xxxx.openai.azure.com/openai/deployments/gpt-4.1-mini"
env_key = "AZURE_OPENAI_API_KEY"
params = { api-version = "2025-01-01-preview" }
wire_api = "chat"

params is not the right field, you need query_params.

 model_provider = "azure"
 model = "gpt-4.1-mini"
 
 [model_providers.azure]
 name = "Azure"
 base_url = "https://xxxx.openai.azure.com/openai/deployments/gpt-4.1-mini"
 env_key = "AZURE_OPENAI_API_KEY"
-params = { api-version = "2025-01-01-preview" }
+query_params = { api-version = "2025-04-01-preview"}
 wire_api = "chat"

jepio avatar Jul 30 '25 08:07 jepio

@jepio Thanks! it finally worked

ken19980727 avatar Aug 05 '25 06:08 ken19980727