Codex CLI not working with Azure provider - stream error: error sending request for url

Resolved 💬 8 comments Opened Sep 22, 2025 by Techie5879 Closed Jan 10, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.39.0

Which model were you using?

gpt-5

What platform is your computer?

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

I have the following config

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

[model_providers.azure]
name = "Azure"
base_url = "https://<azure_endpoint_resource>.openai.azure.com/openai/v1"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "responses"
query_params = { api-version="2025-04-01-preview" }

For all requests - I get:
⚠️ stream error: error sending request for url (https://<azure_endpoint_resource>.openai.azure.com/openai/v1/chat/completions?api-version=2025-04-01-preview); retrying 1/5 in 198ms…
....

It retries 5 times and then exits. The API key is exported. I've tried versions of the base_url, removing the v1 as well.

What is the expected behavior?

_No response_

What do you see instead?

_No response_

Additional information

_No response_

View original on GitHub ↗

8 Comments

Techie5879 · 10 months ago

Logs do not provide any more information than:

stream disconnected - retrying turn (3/5 in 756ms)...

mrbullwinkle · 10 months ago

@Techie5879 two things to try as I am unable to repro your issue with my Azure account on WSL.

<img width="1510" height="1755" alt="Image" src="https://github.com/user-attachments/assets/903eb8fd-1db5-4c79-a2b6-aff96c40974f" />

When testing with the new v1 GA API don't pass api-version it should only be required with the older versions. This is what my file looks like:

```config.toml
model = "gpt-5" # Replace with your actual Azure model deployment name
model_provider = "azure"
model_reasoning_effort = "high"

[model_providers.azure]
name = "Azure OpenAI"
base_url = "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "responses"


Also make sure you are passing your key as an environment variable and not directly passing the key as a string in the file. If I pass the key directly in the file without an environment variable I get the same 401 error.

We also have updated guidance for Codex with Azure here: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/codex?tabs=npm
jakeatmsft · 9 months ago

@Techie5879 - the fix https://github.com/openai/codex/issues/1552, worked for me

Techie5879 · 9 months ago
When testing with the new v1 GA API don't pass api-version it should only be required with the older versions. This is what my file looks like: model = "gpt-5" # Replace with your actual Azure model deployment name model_provider = "azure" model_reasoning_effort = "high" [model_providers.azure] name = "Azure OpenAI" base_url = "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1" env_key = "AZURE_OPENAI_API_KEY" wire_api = "responses" Also make sure you are passing your key as an environment variable and not directly passing the key as a string in the file. If I pass the key directly in the file without an environment variable I get the same 401 error though that error is not helpful in that it is also the error you would get if you were hitting a quota issue. We also have updated guidance for Codex with Azure here: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/codex?tabs=npm

@mrbullwinkle - Tried - did not work. Still getting the same error. And yes I've been exporting the key properly as an env variable and not passing it as string in the file. Can confirm no quota issue as I can query the same deployment fine with the openai python package tho.

Techie5879 · 9 months ago
@Techie5879 - the fix #1552, worked for me

This work. Does seem like the npm package is broken.

cosmic-flood · 8 months ago
> @Techie5879 - the fix #1552, worked for me This work. Does seem like the npm package is broken.

Hi, what did you do to let it work? I am still unable to work with it

Techie5879 · 8 months ago
Hi, what did you do to let it work? I am still unable to work with it

https://github.com/openai/codex/issues/1552#issuecomment-3066563153

Download the linux binary and put it somewhere - use it - and alias codex to that location and seemed to work great for me.

etraut-openai contributor · 6 months ago

Closing out stale bugs.