Azure Access Denied 401custom endpoint

Resolved 💬 4 comments Opened Sep 2, 2025 by Ark-Levy Closed Nov 3, 2025

What version of Codex is running?

0.27

Which model were you using?

gpt 4o

What platform is your computer?

Ubuntu

What steps can reproduce the bug?

Description

Codex fails to authenticate with Azure OpenAI deployments that use custom API Management (APIM) endpoints ending in .azure-api.net instead of the standard .openai.azure.com. This results in a 401 Unauthorized error even with valid API keys.

Configuration

model = "<deployment>"
model_provider = "azure"

[model_providers.azure]
name = "Azure"
base_url = "https://*****.azure-api.net/openai2/openai/deployments/<deployment>"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "chat"
query_params = { "api-version" = "2024-03-01-preview" }

My guess

I guess The authentication logic in Codex only detects .openai.azure.com URLs as Azure endpoints, causing it to send Authorization: Bearer instead of the required api-key header for custom APIM endpoints.

What is the expected behavior?

I want to use codex

What do you see instead?

stream error: unexpected status 401 Unauthorized: { "statusCode": 401, "message": "Access denied due to a missing application credentials or subscription key. Make sure to include an application token or a subscription key when making requests to the API." }; retrying 5/5 in 3.476s…

Additional information

Similar to https://github.com/openai/codex/issues/1842

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗