Prerequisites
- An Azure subscription - Create one for free
- Contributor permissions in Microsoft Foundry.
homebrew(macOS) or Node.js withnpmfor installing the Codex CLI. See Downloading and installing Node.js and npm.- For Windows, install and configure WSL2. See Install WSL.
| Requirements | Details |
|---|---|
| Operating systems | macOS 12+, Ubuntu 20.04+/Debian 10+, or Windows 11 via WSL2 |
| Git (optional, recommended) | 2.23+ for built-in pull request helpers |
| RAM | 4-GB minimum (8-GB recommended) |
Deploy a model in Foundry
- Go to Foundry and create a new project.
- From the model catalog select a reasoning model such as
gpt-5.3-codex,gpt-5.2-codex,gpt-5.1-codex-max,gpt-5.1-codex,gpt-5.1-codex-mini,gpt-5-codex,gpt-5,gpt-5-mini, orgpt-5-nano. - To deploy the model from the model catalog, select Use this model. If you’re using the Azure OpenAI Deployments pane, select deploy model.
- Copy the endpoint URL and the API Key.
Install the Codex CLI
From the terminal, run the following commands to install Codex CLI- npm
- brew
Create and configure config.toml
-
To use Codex CLI with Azure, create and set up a
config.tomlfile. Store theconfig.tomlfile in the~/.codexdirectory. Create aconfig.tomlfile inside this directory or edit the existing file if it already exists: -
Copy the following text to use the v1 Responses API. With the v1 API you no longer need to pass
api-version, but you must include/v1in thebase_urlpath. You can’t pass your API key as a string directly toenv_key.env_keymust point to an environment variable. Update yourbase_urlwith your resource name: -
After you save the updates to your
config.tomlfile, return to the terminal and create an instance of the environment variable that the config file references. -
Run one of the following commands in the terminal to test if your Codex CLI configuration was successful:
Command Purpose codex Launch interactive Terminal User Interface (TUI) codex “Initial prompt” Launch TUI with an initial prompt codex exec “Initial prompt” Launch TUI in non-interactive “automation mode”
Use Codex in Visual Studio Code
You can also use Codex directly inside Visual Studio Code when using the OpenAI Codex extension.- If you don’t already have Visual Studio Code, install it for macOS and Linux.
-
Install the OpenAI Codex extension. The extension relies on your
config.tomlfile that you configured for Codex CLI. -
If you’re in a new terminal session, set up the environment variable for
AZURE_OPENAI_API_KEY:
If you use WSL, also set the same environment variable on the Windows host so the extension can read it when needed.
-
Launch VS Code from the same terminal session. (Launching from an app launcher can result in your API key environment variable not being available to the Codex extension.)
- You can now use Codex in Visual Studio Code to chat, edit, and preview changes while toggling between three approval modes.
Approval modes
Approval modes determine how much autonomy and interaction you want to have with Codex.| Approval mode | Description |
|---|---|
| Chat | To chat and plan with the model. |
| Agent | Codex can read files, make edits, and run commands in the working directory automatically. Codex needs approval for activities outside the working directory or to access the internet. |
| Agent (full access) | All the capabilities of Agent mode without the need for step-by-step approval. Don’t use full access mode without full understanding of the potential risks as well as implementing additional guardrails such as running in a controlled sandbox environment. |
We recommend reviewing OpenAI’s guidance on Codex security.
Persistent guidance with AGENTS.md
You can give Codex extra instructions and guidance by usingAGENTS.md files. Codex looks for AGENTS.md files in the following places and merges them top-down, giving it context about your personal preferences, project-specific details, and the current task:
~/.codex/AGENTS.md– personal global guidance.AGENTS.mdat your repository’s root – shared project notes.AGENTS.mdin the current working directory – subfolder or feature specifics.
AGENTS.md in your project root with the following content, derived from the Azure AI Agents SDK documentation:
\ characters.
Experiment with Codex CLI
Launch codex with the following initial prompt:Codex in GitHub Actions
Codex can execute as part of your continuous integration (CI) pipeline. Store your API key in the repository’s secret store asAZURE_OPENAI_KEY and add a job like this to automatically update your changelog before a release:
Troubleshooting
| Symptom | Solution |
|---|---|
401 Unauthorized or 403 Forbidden | Export your AZURE_OPENAI_API_KEY environment variable correctly. Confirm that your key has project/deployment access. Make sure you aren’t passing the API Key as a string directly to the env_key in the config.toml file. You must pass a valid environment variable. |
ENOTFOUND, DNS error, or 404 Not Found | Verify base_url in config.toml uses your resource name, correct domain, and contains /v1. For example, base_url = "https://<your-resource>.openai.azure.com/openai/v1". |
| CLI ignores Azure settings | Open ~/.codex/config.toml and ensure: - model_provider = "azure" is set. - The [model_providers.azure] section exists. - env_key = "AZURE_OPENAI_API_KEY" matches your environment variable name. |
| Entra ID support | Entra ID support is currently not available for Codex. |
401 Unauthorized only with the WSL + VS Code Codex extension | When running VS Code from inside WSL with the Codex extension the extension might check for the API key environment variable on the local Windows host rather than within the terminal shell that launched VS Code. To mitigate this issue, set the environment variable on the local Windows host as well, then launch a new terminal from WSL and launch VS Code with code .. |