How to properly configure model_providers for Azure

Open 💬 11 comments Opened Aug 20, 2025 by Soorma718

What version of Codex is running?

0.22.0

Which model were you using?

gpt-5

What platform is your computer?

wsl

What steps can reproduce the bug?

projects = { "/home/-/.codex" = { trust_level = "trusted" } }
[model_providers.azure]
name = "Azure"
# Make sure you set the appropriate subdomain for this URL.
base_url = "https://<>.openai.azure.com/openai"
env_key = "AZURE_API_KEY"  # Or "OPENAI_API_KEY",
query_params = { "api-version" = "2025-04-01-preview" }
wire_api = "responses"

[profiles.5]
model_provider = "azure"
model = "gpt-5"
🖐 error sending request for url (https://<>.openai.azure.com/openai/responses?
api-version=2025-04-01-preview)

/status
📂 Workspace
  • Path: ~/projects/--
  • Approval Mode: on-request
  • Sandbox: workspace-write
  • Session ID: 00-=-0-=---

🧠 Model
  • Name: gpt-5
  • Provider: Azure
  • Reasoning Effort: Medium
  • Reasoning Summaries: Auto

📊 Token Usage
  • Input: 0
  • Output: 0
  • Total: 0

▌ Ask Codex to do anything                                                                                                                               
 ⏎ send   Ctrl+J newline   Ctrl+C quit                                                                                                                    

What is the expected behavior?

_No response_

What do you see instead?

_No response_

Additional information

_No response_

View original on GitHub ↗

11 Comments

ilovetocode · 11 months ago

~~The documented instructions didn't work for me either.~~

~~Below is the configuration that is working for me:~~

this approach broke in release 0.23.0

https://github.com/openai/codex/issues/2480#issuecomment-3209520600 answer is working for me

model_provider = "azure"
model = "gpt-5-mini"
[model_providers.azure]
name = "Azure"
base_url = "<your-base-url>/openai/deployments/gpt-5-mini" <- replace 'gpt-5-mini' with the name of your openai deployment - the base_url that you see in the azure ui might be the /openai one, ignore it and use the one here
env_key = "AZURE_OPENAI_API_KEY"
query_params = { api-version = "2025-04-01-preview" }
wire_api = "chat" <- important
Soorma718 · 11 months ago
wire_api = "chat" <- important

Thanks for the response, unfortunately still no luck.

Erivess · 11 months ago

Its also not working for me

Amairatech · 11 months ago

please help

Erivess · 11 months ago

I got it working like this now - I was previously editing the config.toml in the project directory, thats why it didnt pickup the changes.

[model_providers.azure]
name = "Azure"
# Replace YOUR_RESOURCE_NAME
base_url = "https://INSERTHERE.openai.azure.com/openai"
env_key = "AZURE_OPENAI_API_KEY"
# Replace api-version if needed
query_params = { api-version = "2025-04-01-preview" }
wire_api = "responses"

# Optional profile so you can switch easily
[profiles.azure_gpt5]
model_provider = "azure"
# Replace with your Azure deployment name
model = "gpt-5"

# Optional: prefer API key auth over ChatGPT login
preferred_auth_method = "apikey"
model_reasoning_effort = "high"
model_reasoning_summary = "detailed"

I run the cli like this:

export AZURE_OPENAI_API_KEY=“INSERT “KEY
codex --profile azure_gpt5
Soorma718 · 10 months ago
I got it working like this now - I was previously editing the config.toml in the project directory, thats why it didnt pickup the changes. `` [model_providers.azure] name = "Azure" # Replace YOUR_RESOURCE_NAME base_url = "https://INSERTHERE.openai.azure.com/openai" env_key = "AZURE_OPENAI_API_KEY" # Replace api-version if needed query_params = { api-version = "2025-04-01-preview" } wire_api = "responses" # Optional profile so you can switch easily [profiles.azure_gpt5] model_provider = "azure" # Replace with your Azure deployment name model = "gpt-5" # Optional: prefer API key auth over ChatGPT login preferred_auth_method = "apikey" model_reasoning_effort = "high" model_reasoning_summary = "detailed" ` I run the cli like this: ` export AZURE_OPENAI_API_KEY=“INSERT “KEY codex --profile azure_gpt5 ``

same error still for me with your config stream error: error sending request for url (https://*********.openai.azure.com/openai/responses?api-version=2025-04-01-preview); retrying 1/5 in
188ms…

MijeongJeon · 10 months ago

I had the same error and struggled with it for a while, so I’d like to share what worked for me.
The important part was the base_url format and the wire_api setting.

  1. For gpt-5 series(gpt-5, gpt-5-mini, gpt-5-chat...), it doesn’t work with responses api — it needs to use the chat completions API, so wire_api = "chat".
  2. base_url format is like this

https://<YOUR-RESOURCE-NAME>.cognitiveservices.azure.com/openai/deployments/<MODEL_DEPLOYMENT_NAME>/

Here’s the config snippet that finally worked:

model_provider = "azure"
model          = "gpt-5"

[model_providers.azure]
name         = "Azure"
base_url     = "https://<YOUR-RESOURCE-NAME>.cognitiveservices.azure.com/openai/deployments/gpt-5/"
env_key      = "AZURE_OPENAI_API_KEY"
wire_api     = "chat"
query_params = { api-version = "2025-04-01-preview" }

I tested with different URL formats, but only this structure with wire_api = "chat" worked for me.
Hope this helps anyone facing the same issue :)

doggy8088 · 10 months ago

error sending request for url (https://RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview); retrying 1/5 in 202ms…" }) }
[2025-09-01T15:36:18] stream error: error sending request for url (https://RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview) is related to my issue https://github.com/openai/codex/issues/1552

ksquarekumar · 10 months ago
model = "<YOUR-DEPLOYMENT-NAME>"
model_provider = "<YOUR-PROVIDER-NAME>"
profile = "<YOUR-PROFILE-NAME>"

[model_providers."<YOUR-PROVIDER-NAME>"]
name = "Azure"
base_url = "https://<YOUR-RESOURCE-NAME>.openai.azure.com/openai/v1/"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "responses" # Changed from "chat", works as of v1 api GA, recommended by OpenAI
request_max_retries = 4
stream_max_retries = 10
stream_idle_timeout_ms = 300000

[profiles."<YOUR-PROFILE-NAME>"]
model = "<YOUR-DEPLOYMENT-NAME>"
model_provider = "<YOUR-PROVIDER-NAME>"

Works for me

jakeatmsft · 9 months ago
error sending request for url (https://RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview); retrying 1/5 in 202ms…" }) } [2025-09-01T15:36:18] stream error: error sending request for url (https://RESOURCE-NAME.openai.azure.com/openai/responses?api-version=2025-04-01-preview) is related to my issue #1552

Thank you for the fix #1552, this was killing me!

doggy8088 · 9 months ago

@jakeatmsft Exactly! That issue has been bothering me for several months!