Cannot use Azure OpenAI with Codex – no_kv_space / “stream disconnected before completion” on every request
What version of Codex is running?
codex-cli 0.71.0
What subscription do you have?
API Key based Azure OpenAI
Which model were you using?
gpt-5.2
What platform is your computer?
Darwin 25.1.0 arm64 arm
What issue are you seeing?
When using Azure as the provider for Codex, every request fails with a streaming error, even for trivial prompts like “hello”.
The UI shows “stream disconnected before completion”, and the underlying trace from Azure contains no_kv_space, which indicates a failure inside the Azure/OpenAI backend rather than an invalid request from the client.
Using the same Azure resource and model outside Codex (direct API / SDK) works as expected, so the issue seems specific to the Codex–Azure integration path.
<img width="1176" height="330" alt="Image" src="https://github.com/user-attachments/assets/a86fd160-aa7e-45c5-833a-9355a4469ccc" />
<img width="1336" height="255" alt="Image" src="https://github.com/user-attachments/assets/247013ce-df90-47e0-958f-263a81968d2b" />
What steps can reproduce the bug?
- Configure Codex to use Azure OpenAI (set OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, and select the Azure deployment as the model).
- Start a new Codex session.
- Send a very simple request, e.g. hello or “Explain this codebase”.
- Wait for the response.
What is the expected behavior?
Codex should stream a normal completion from the Azure OpenAI deployment, just as it does with the non-Azure OpenAI endpoint.
Additional information
The request starts but fails mid-stream with a message similar to:
“stream disconnected before completion” (or equivalent error message in the Codex UI).
Azure’s trace includes no_kv_space indicating the backend GPU KV-cache runs out of capacity and aborts the request, while still returning HTTP 200 on the outer response.
This happens consistently for all prompts, including very small ones, making Azure effectively unusable as a provider.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗