How to use Azure provider
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!
Hi everyone,
I installed Codex CLI using the following command:
npm i -g @openai/codexThe 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
@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
@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?
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"
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!
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 😄)
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:
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?
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:
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-previewor 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"
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!
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"
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:
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.1wire_api=responses:
- base_url must end in
/openai:https://xxxxxxxxxxx.cognitiveservices.azure.com/openai- api-version should be
2025-04-01-previewor 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.
Could you help me identify what might be going wrong?
Thanks in advance!
I’ve updated my
config.tomlas 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 Thanks! it finally worked
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?