Share via

Setup Codex CLI with Azure AI service

Avnish Midha 20 Reputation points
2025-11-02T03:46:35.3566667+00:00

Have been trying to setup Codex CLI with Azure AI Services, but it has not worked yet. Tried it with Azure Foundry Service, Azure OpenAI, Azure AI but has not worked, also the documentation is lacking, the only one available does not work: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/codex?tabs=npm

Request tried and tested documentation that works now. Thanks.

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform

0 comments No comments

Answer accepted by question author

  1. Amira Bedhiafi 41,386 Reputation points MVP Volunteer Moderator
    2025-11-02T13:08:58.1633333+00:00

    Hello Avnish !

    Thank you for posting on Microsoft Learn Q&A.

    You need to install the Codex CLI :

    # either one works
    npm install -g @openai/codex
    codex --version
    brew install codex
    codex --version
    

    https://developers.openai.com/codex/cli/

    Codex needs a provider block and must talk to the v1 Responses endpoint (note the /openai/v1 path and no api-version query).

    https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/codex

    # ~/.codex/config.toml
    model = "gpt-5-codex"            # or your deployment name
    model_provider = "azure"
    model_reasoning_effort = "medium"
    [model_providers.azure]
    name     = "Azure OpenAI"
    base_url = "https://YOUR_RESOURCE_NAME.openai.azure.com/openai/v1"
    env_key  = "AZURE_OPENAI_API_KEY"
    wire_api = "responses"
    

    Then export your Azure OpenAI resource key since Entra ID auth isn’t supported by Codex yet :

    # Linux/macOS/WSL
    export AZURE_OPENAI_API_KEY="YOUR_AOAI_KEY"
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.