Azure OpenAI Python SDK works, but codex CLI fails with 404

Resolved 💬 5 comments Opened Apr 17, 2025 by adhishthite Closed Aug 7, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator) responded on this thread — see the highlighted reply below.

📓 Context

I’m able to successfully connect to Azure OpenAI using the Python SDK with the following code:

import os
from openai import AzureOpenAI

endpoint = "https://REDACTED.openai.azure.com/"
deployment = "o4-mini"
subscription_key = "REDACTED"
api_version = "2025-03-01-preview"

client = AzureOpenAI(
    api_version=api_version,
    azure_endpoint=endpoint,
    api_key=subscription_key,
)

response = client.chat.completions.create(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "I am going to Paris, what should I see?"}
    ],
    max_completion_tokens=100000,
    model=deployment
)

print(response.choices[0].message.content)

This works as expected and returns a valid completion from the o4-mini deployment.

---

❗ Issue

However, when I attempt to use the Codex CLI with the following environment variables:

export OPENAI_API_KEY="REDACTED"
export OPENAI_API_TYPE="azure"
export OPENAI_BASE_URL="https://REDACTED.openai.azure.com/"
export OPENAI_API_VERSION="2025-03-01-preview"

and run:

codex

and ask a question, I get this:

⚠️  OpenAI rejected the request. Error details: 
Status: 404, Code: 404, Type: unknown, 
Message: 404 Resource not found. Please verify your settings and try again.

I also tried setting these values in .codex/config.yaml but still got the same error.

---

🔍 Ask

Could someone help confirm:

  1. Is Codex CLI compatible with Azure OpenAI?
  2. If yes, what’s the correct way to configure it for a custom deployment like o4-mini?
  3. Is there a different env var required for specifying the deployment name?

Would appreciate a quick fix or workaround here—blocking usage on our end. Thanks!

<img width="794" alt="Image" src="https://github.com/user-attachments/assets/8ddcb0f0-68d7-451a-9f34-7be1c5c71e0f" />

View original on GitHub ↗

5 Comments

tibo-openai collaborator · 1 year ago

There is an open PR here:
https://github.com/openai/codex/pull/92

Could you try it and comment there if it doesn't work?

adhishthite · 1 year ago

@tibo-openai Done! :) Looking forward to getting this integrated soon!

piyushptiwari1 · 1 year ago

Hi @adhishthite Is your issue resolved? I am also facing the same issue

vishal9483 · 1 year ago

I am also facing same issue. Anyone has any update on this?

codex-maintainers · 1 year ago

Thank you for the detailed feedback! Please try using the latest version of Codex CLI, as we're actively working on improvements and fixes. If the issue persists, we'd appreciate it if you could try contributing a fix to the codex-rs/ implementation. More details on our project update can be found here.