Feature: Entra authentication for Azure OpenAI provider
Resolved 💬 6 comments Opened May 20, 2025 by markwaddle Closed Aug 7, 2025
the simplest solution would be to use the DefaultAzureCredential() from the @azure/identity package.
this is needed by organizations whom only allow Entra authentication to their Azure OpenAI endpoints
suggestion:
- if the API key env var is set, use API key auth
- if the API key env var is unset, use Entra auth
- add
@azure/identityas an optional dependency
6 Comments
In case it can help someone, this is how I do it in the meantime:
and then as a token you pass the following:
Thanks for the feedback! We're primarily focused on the native/Rust implementation of Codex CLI. Please try the latest version to see if this is still an issue. If it is, we'd be happy to consider a PR to the
codex-rs/implementation.I cannot get this to work with my deployment using responses https://[resource].openai.azure.com/openai/v1/responses , any tips?
■ unexpected status 401 Unauthorized: Access denied due to invalid subscription key or wrong API endpoint. Make sure to
provide a valid key for an active subscription and use a correct regional API endpoint for your resource., url:...
This works with API_KEY but I get the error when switching to Token auth.
UPDATED PROGRESS:
For reasons unknown, using the az cli to provide token in my WSL was not working, I was able to use the python azure-identity library to provide a working token. I added the following lines to my .bashrc:
````
$ export AZURE_OPENAI_API_KEY="$(python3 - <<'PY'
from azure.identity import DefaultAzureCredential
print(DefaultAzureCredential().get_token("https://cognitiveservices.azure.com/.default").token)
PY
)"
$ echo "[bashrc] AZURE_OPENAI_API_KEY set (len=${#AZURE_OPENAI_API_KEY})"
I have the following configuration:
which is working when AZURE_OPENAI_API_KEY environment variable has the Azure Foundry key but not when i place the user token as value from the below command:
az account get-access-token --resource=https://cognitiveservices.azure.com/ --query accessToken --output tsvI had same issue trying to use az cli to get the token, my fix was to use python azure-identity (https://github.com/openai/codex/issues/1056#issuecomment-4070426232)