Skip to content

Feature: Entra authentication for Azure OpenAI provider #1056

Closed

Description

@markwaddle

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/identity as an optional dependency

Activity

  1. MattFanto commented on Jul 21, 2025

    @MattFanto

    In case it can help someone, this is how I do it in the meantime:

    model_provider = "azure"
    provider = "azure"
    model = "<deployment name>"  # Your deployment name, NOT the AI model name
    
    [model_providers.azure]
    name         = "Azure OpenAI"
    base_url     = "https://<resource>.openai.azure.us/openai/deployments/<deployment name>"
    env_key      = "AZURE_OPENAI_API_KEY"
    query_params = { api-version = "2025-01-01-preview" }
    

    and then as a token you pass the following:

    AZURE_OPENAI_API_KEY=$(az account get-access-token --resource=https://cognitiveservices.azure.com/ --query accessToken --output tsv) \
    codex
    
  2. codex-maintainers commented on Aug 7, 2025

    @codex-maintainers

    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.

  3. jakeatmsft commented on Mar 16, 2026

    @jakeatmsft

    In case it can help someone, this is how I do it in the meantime:

    model_provider = "azure"
    provider = "azure"
    model = "<deployment name>"  # Your deployment name, NOT the AI model name
    
    [model_providers.azure]
    name         = "Azure OpenAI"
    base_url     = "https://<resource>.openai.azure.us/openai/deployments/<deployment name>"
    env_key      = "AZURE_OPENAI_API_KEY"
    query_params = { api-version = "2025-01-01-preview" }
    

    and then as a token you pass the following:

    AZURE_OPENAI_API_KEY=$(az account get-access-token --resource=https://cognitiveservices.azure.com/ --query accessToken --output tsv) \
    codex
    

    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.

  4. jakeatmsft commented on Mar 16, 2026

    @jakeatmsft

    In case it can help someone, this is how I do it in the meantime:

    model_provider = "azure"
    provider = "azure"
    model = "<deployment name>"  # Your deployment name, NOT the AI model name
    
    [model_providers.azure]
    name         = "Azure OpenAI"
    base_url     = "https://<resource>.openai.azure.us/openai/deployments/<deployment name>"
    env_key      = "AZURE_OPENAI_API_KEY"
    query_params = { api-version = "2025-01-01-preview" }
    

    and then as a token you pass the following:

    AZURE_OPENAI_API_KEY=$(az account get-access-token --resource=https://cognitiveservices.azure.com/ --query accessToken --output tsv) \
    codex
    

    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})"
    
    
  5. koureasstavros commented on Apr 21, 2026

    @koureasstavros

    I have the following configuration:

    model = "GPT54-GS" # Replace with your actual Azure model deployment name
    model_provider = "azure"
    model_reasoning_effort = "medium"
    
    [model_providers.azure]
    name = "Azure OpenAI"
    base_url = "https://<myfoundry>.openai.azure.com/openai/v1" # Replace with your actual Azure foundry name
    env_key      = "AZURE_OPENAI_API_KEY"
    wire_api = "responses"
    

    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 tsv

  6. jakeatmsft commented on Apr 21, 2026

    @jakeatmsft

    I have the following configuration:

    model = "GPT54-GS" # Replace with your actual Azure model deployment name
    model_provider = "azure"
    model_reasoning_effort = "medium"
    
    [model_providers.azure]
    name = "Azure OpenAI"
    base_url = "https://<myfoundry>.openai.azure.com/openai/v1" # Replace with your actual Azure foundry name
    env_key      = "AZURE_OPENAI_API_KEY"
    wire_api = "responses"
    

    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 tsv

    I had same issue trying to use az cli to get the token, my fix was to use python azure-identity (#1056 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions