Artificial Intelligence Jul 8, 2026 11 min read

How To Set Up OpenAI Codex with Azure OpenAI Models: Step-by-Step Windows Guide

YouTube Thumbnail

If you are already using Azure OpenAI in your Microsoft subscription, you can connect those models to the Codex app and keep your AI coding workflow inside the tools you already manage. This guide walks through the full setup in a practical way, from installing Codex, opening the configuration file, adding your Azure endpoint, storing the API key safely in Windows, and testing that Codex can respond using your Azure model.

A clean modern developer workspace with a Windows laptop showing an AI coding assistant interface, Azure cloud icons on a second monitor, natural daylight, white desk, blue accent lighting, professional personal brand style.

The Codex app can use different model providers. By default, it may connect to the standard provider connected to your account, but if you have Azure OpenAI access, you can point Codex to your Azure resource instead.

This is useful if your organisation already manages access, billing, security, and model deployments through Azure. It also keeps your development work aligned with the same environment you might already be using for business projects, internal tools, or client work.

Key idea: Codex needs two main things to talk to Azure OpenAI: the Azure endpoint in the config file, and the API key stored as an environment variable in Windows.

Item Purpose Where You Get It
Codex app The coding assistant interface you will use OpenAI developer download page or ChatGPT app prompt
config.toml file Stores the model provider setup Codex profile settings
Azure OpenAI endpoint Tells Codex where to send model requests Azure AI Foundry resource details
API key Authenticates the request to Azure Azure AI Foundry resource keys
Environment variable Stores the API key outside the config file Windows system environment variables

Before you start, make sure you have access to an Azure subscription with an Azure OpenAI or Azure AI Foundry resource already available. You also need a model deployment in that resource. The deployment name is important because Codex will use it when sending requests.

Install Codex And Open The Configuration File

If you already have the Codex app installed, you can skip this first part and go straight to the configuration section. If not, install it first from the developer download page. In the video, I used the Windows version.

When you go to the developer page, select the app option, then choose the Windows download. If you already have the ChatGPT app installed, you may also see an option to install Codex from there. Either approach should get you to the same point, which is having the Codex app available on your computer.

HOW_TO_USE_AZURE_OPENAI_MODELS_IN_CODEX_APP-0-00-46.png

After installation, open Codex and log in with your account. Once you are inside the app, go to your profile area, then open your profile settings. Under the configuration section, you should see the user config option. This is where the app lets you open the config.toml file.

You can open this file with Notepad, Visual Studio Code, or any plain text editor. I used Notepad in the walkthrough because it is already available on Windows and is simple enough for this job.

The config file controls which model Codex uses, which provider it connects to, how much reasoning effort it applies, and where it should look for the API key.

A close view of a Windows laptop screen with a plain text configuration file open beside an Azure cloud dashboard, clean white interface, blue highlights, practical developer setup, realistic lighting.

Add The Azure Provider Details

Inside the config.toml file, you need to add the model and provider configuration. The exact values can vary depending on your Codex app version and your Azure deployment, but the structure is generally based around these core fields.

model = "your_model_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"
env_key = "AZURE_OPENAI_KEY"

The most important part here is the base_url. This must match the Azure endpoint from your Azure AI Foundry resource. If the endpoint is wrong, Codex will not know where to send the request, even if your API key is correct.

The env_key value is also important. Do not paste your actual Azure API key directly into the config file. Instead, write the name of the environment variable that will store the key. In this example, the environment variable name is AZURE_OPENAI_KEY.

Config Field What It Means Practical Tip
model The Azure model deployment Codex will use Use the deployment name from Azure, not just the model family name
model_provider The provider profile Codex should use Match this to the provider block name
model_reasoning_effort How much reasoning the model should apply Start with medium to control cost and speed
base_url Your Azure OpenAI endpoint Copy it directly from Azure AI Foundry
env_key The Windows environment variable name Keep the same name when you create the variable

Reasoning effort can make a difference depending on what you are asking Codex to do. For simple edits, quick scripts, and basic questions, medium is normally a good starting point. If you are doing deeper code analysis, architecture review, or more complex generation, you can test high or extra high. Just remember that higher reasoning can use more tokens and may cost more through your Azure subscription.

Find The Endpoint In Azure AI Foundry

Next, open Microsoft Azure AI Foundry and go to your resources. In the walkthrough, I selected the existing resource that was already created. If you do not have one yet, you can create a new resource from the Azure portal or Azure AI Foundry, depending on your setup.

HOW_TO_USE_AZURE_OPENAI_MODELS_IN_CODEX_APP-0-02-50.png

Once you open the resource, look for the section that shows the resource details. The key items are the API key, the project endpoint, and the Azure OpenAI endpoint. For the Codex config, the Azure OpenAI endpoint is the main one you need.

Copy the Azure OpenAI endpoint and paste it into the base_url field in your config file. Make sure you copy the endpoint cleanly. Extra spaces at the beginning or end can cause frustrating errors later.

HOW_TO_USE_AZURE_OPENAI_MODELS_IN_CODEX_APP-0-03-23.png

After pasting the endpoint into the config file, save the file and close the editor. At this stage, the config tells Codex which provider to use and where that provider lives, but it still needs a valid key to authenticate.

Store The API Key In Windows

The next step is to create a Windows environment variable for your Azure OpenAI API key. This is better than storing the key directly in the config file because it keeps your credential separate from the visible app settings.

On Windows, open the Start menu and search for environment variables. Choose Edit the system environment variables. In the window that opens, select Environment Variables.

You can create the variable under your user variables or under system variables. In the video, I used the system variables section so the key could be available more broadly on the computer. If you are on a shared computer, be careful with system variables because other users may be able to access them.

  1. Click New under the environment variable section you want to use.
  2. For the variable name, enter AZURE_OPENAI_KEY.
  3. For the variable value, paste your Azure OpenAI API key.
  4. Click OK to save it.
  5. Click OK again to close the environment variable windows.
  6. Generated infographic

Use the exact same name that you placed in the env_key field. If the config says AZURE_OPENAI_KEY, then the Windows variable must also be AZURE_OPENAI_KEY. If one letter is different, Codex will not find it.

Security note: Treat your Azure API key like a password. Do not share it in screenshots, code samples, public repositories, or support messages.

After saving the environment variable, restart your computer. In some cases, restarting the Codex app may be enough, but a full restart is the cleanest way to make sure Windows has loaded the new variable properly.

Test Codex With The Azure Model

Once your computer has restarted, open Codex again. A quick way to check whether the configuration is working is to send a very simple message. In the walkthrough, I used a basic greeting first. If the model replies, that is a good sign that the endpoint and API key are working.

HOW_TO_USE_AZURE_OPENAI_MODELS_IN_CODEX_APP-0-05-25.png

You may also notice that the app no longer displays the same free model label that you saw previously. That can be a useful visual clue that Codex is now using the configured provider instead of the default option.

If the app returns an error about the API key, go back and check the environment variable. The most common issues are a copied key with missing characters, a different variable name in the config file, or the app not being restarted after the variable was added.

After the simple test worked, I asked Codex to create a basic Hello World example with random colours. This is a nice practical test because it asks the app to generate actual code, apply a small creative instruction, and then update the result with another change.

For example, you can test with prompts like these:

  • Write me a simple Hello World with random colours.
  • Change the letters to be random colours.
  • Make the page refresh the colours when I click a button.
  • Explain what each part of the code does.

In the video, Codex generated the small example, then updated it when I asked for random letter colours. This confirms that Codex can not only answer a chat message, but also work through code changes using the Azure model.

HOW_TO_USE_AZURE_OPENAI_MODELS_IN_CODEX_APP-0-07-11.png

Quick Troubleshooting Reference

If something does not work on the first attempt, do not panic. Most setup issues are small configuration mismatches. Use this checklist to work through the likely causes.

Problem Likely Cause What To Check
Codex says the API key is invalid The key was copied incorrectly or the wrong key was used Copy a fresh key from Azure and update the environment variable
Codex cannot find the key The variable name does not match Compare env_key with the Windows variable name
No change after editing config Codex is still using the old settings Restart Codex or restart Windows
Endpoint error The base URL is wrong Copy the Azure OpenAI endpoint again from Azure AI Foundry
Model not found The deployment name is not correct Use the Azure deployment name, not just the public model name
Responses are slow or costly Reasoning effort is too high for the task Try medium before using high or extra high

Should I Use Medium, High, Or Extra High Reasoning?

For everyday coding tasks, medium is usually a sensible starting point. It gives you a good balance between speed, cost, and quality. Use high when you need more careful reasoning, such as debugging larger blocks of code or planning a more complex feature.

Extra high is useful when you want the model to spend more effort on the answer, but it is not always necessary. If you are experimenting or working through simple examples, medium will usually do the job and keep your Azure usage more controlled.

Why Use An Environment Variable Instead Of The Config File?

Putting the API key directly into a config file may feel convenient, but it is not a great habit. Config files can be copied, shared, backed up, or accidentally shown in a screen recording. An environment variable keeps the secret separate from the app configuration.

This approach also makes it easier to rotate keys later. If you generate a new key in Azure, you can update the Windows environment variable without changing the rest of your Codex setup.

What If I Upgrade Codex Later?

In the walkthrough, the process was shown using version 5.5. The same general process should apply to later versions, such as 5.6, and earlier versions as long as the app supports this configuration method. If the app changes how providers are configured, check the latest Codex documentation and update the config format as needed.

The core idea should remain the same: Codex needs to know the model name, the provider, the Azure endpoint, and the environment variable that contains the API key.

Once Codex replies successfully through your Azure OpenAI setup, you are ready to use it for real coding work. Start with a small prompt, confirm that the model behaves as expected, then move into larger tasks like refactoring, generating test files, explaining unfamiliar code, or building quick prototypes inside your own Azure backed workflow.

Frequently Asked Questions

  • Can I use Azure OpenAI with the Codex app?

    Yes. If you already have access to Azure OpenAI or an Azure AI Foundry resource, you can configure Codex to use your Azure model deployment instead of the default provider.

  • What details do I need from Azure to connect Codex?

    You will need your Azure OpenAI endpoint, an API key, and the model deployment name from your Azure resource. The deployment name is especially important, as Codex uses it when sending requests.

  • Should I paste my Azure API key into the Codex config file?

    No. It is better to store the API key as a Windows environment variable, such as AZURE_OPENAI_KEY, and reference that variable in the config.toml file. This keeps the key out of plain text configuration.

  • Where do I edit the Codex configuration?

    Open the Codex app, go to your profile settings, then find the user configuration option. This will open the config.toml file, which you can edit with Notepad, Visual Studio Code, or another plain text editor.

  • What reasoning effort should I choose?

    medium is a practical starting point for general coding tasks, simple edits, and basic questions. Higher reasoning settings may help with more complex code analysis or architecture work, but they can also use more tokens and increase costs in your Azure subscription.

Follow the journey

Get the next build note in your inbox.

Short updates from Marco on entrepreneurship, products, tools, family milestones, and the daily running streak.

This field is required.

Check your inbox or spam folder to confirm your subscription.