IF.
Notes
codexazurellmaifoundrygpt

How to setup Codex CLI with a model from Azure AI Foundry?

1 min read

I found myself having to test Codex CLI with a couple gpt models (something quite common), but in this case I required to do it using the models from Azure AI Foundry. Of course this has certain limitations (the main one: you are bound to ONLY being able to use the models deployed there), but I just needed to do it to implement Codex in a greater agentic workflow... AND... I needed to do it for Macos, Ubuntu/Debian and Windows.


Steps

  1. Download Codex CLI:
npm i -g @openai/codex
  1. Valide it is installed correctly (you might need to restart your terminal):
codex --version
  1. THE MAGIC! Create or edit the configuration file for codex with the following:

In your home folder (cd ~/.codex) you need to edit (or create if it doesn't exists) the file config.toml with the following:

model = "<model_name_as_is_in_foundry>"
model_provider = "azure"
model_reasoning_effort = "medium" # low, medium, high
 
[model_providers.azure]
name = "Azure OpenAI"
base_url = "https://<your_foundry_endpoint>" # "https://my-endpoint-eastus.cognitiveservices.azure.com/openai/v1"
env_key = "AZURE_OPENAI_API_KEY"
wire_api = "responses"
  1. You need to setup an environment variable AZURE_OPENAI_API_KEY. This variable will be loaded automatically by codex. So either you set it up every time before using codex export AZURE_OPENAI_API_KEY=<your_key> or just set it in your OS for good.

  2. Open codex in any folder: codex and enjoy :).