{"id":1041,"date":"2025-06-17T22:54:11","date_gmt":"2025-06-17T22:54:11","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/all-things-azure\/?p=1041"},"modified":"2025-09-15T18:34:22","modified_gmt":"2025-09-15T18:34:22","slug":"codex-azure-openai-integration-fast-secure-code-development","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/all-things-azure\/codex-azure-openai-integration-fast-secure-code-development\/","title":{"rendered":"Codex Azure OpenAI Integration: Fast &#038; Secure Code Development"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">You can now enjoy the same Codex experience in CLI or VS Code with Azure OpenAI support. We&#8217;ve contributed the following five pull requests to make this possible, giving you the familiar Codex functionality from ChatGPT while running securely on Azure:<\/span><\/p>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><a href=\"https:\/\/github.com\/openai\/codex\/pull\/769\">PR\u00a0#769<\/a><\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><a href=\"https:\/\/github.com\/openai\/codex\/pull\/1324\">PR\u00a0#1324<\/a><\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><a href=\"https:\/\/github.com\/openai\/codex\/pull\/1321\">PR\u00a0#1321<\/a><\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><a href=\"https:\/\/github.com\/openai\/codex\/pull\/1778\">PR\u00a0#1778<\/a> (awaiting merge &#8211; Entra\u00a0ID token-based authentication related to <a href=\"https:\/\/github.com\/openai\/codex\/pull\/92\">PR\u00a0#92<\/a>)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">We are collaborating with OpenAI on additional updates and integrations, so stay tuned. Meanwhile, follow the steps below to get Codex running on your Azure subscription.<\/span><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">OpenAI\u2019s <a href=\"https:\/\/github.com\/openai\/codex\"><strong>Codex CLI<\/strong><\/a> is the same coding agent that powers <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">ChatGPT\u2019s Codex. You can now run this<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">coding agent <em>entirely on Azure infrastructure<\/em>, which keeps <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">your data inside your compliance boundary and gives you the advantages <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">of enterprise-grade security, private networking, role-based access control, <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">and predictable cost management. Codex is more than a chat with your code agent &#8211; it is an<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\"><strong>asynchronous coding agent<\/strong> that can be triggered from your terminal, VS Code, or from a<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">GitHub Actions runner, automatically opening pull requests, refactoring files, <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">and writing tests with the credentials of your Azure OpenAI deployment.<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">Explore deploying it with Azure OpenAI for use cases such as language translation, data-to-code, and <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">legacy migration as detailed in the original <a href=\"https:\/\/openai.com\/index\/introducing-codex\/\" target=\"_blank\" rel=\"noopener\">\nIntroducing Codex blog post<\/a>.<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">After you are up and running, visit <a href=\"https:\/\/aifoundry.app\" target=\"_blank\" rel=\"noopener\">aifoundry.app<\/a> (and <a href=\"https:\/\/asyncloom.com\" target=\"_blank\" rel=\"noopener\">asyncloom.com<\/a>) to<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">configure your repository for Codex and to browse a growing catalog of other<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">Azure-hosted coding agents, including GitHub Copilot Coding Agent, Cognition<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">Devin, SRE Agent, and more.<\/span><\/p>\n<p><iframe title=\"YouTube video player\" src=\"\/\/www.youtube.com\/embed\/H7LJJYzGym0?si=bCOuh9ybXSxS8748&amp;start=156\" width=\"140\" height=\"79\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Prerequisites<\/span><\/h3>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">An active Azure subscription with access to <strong>Azure OpenAI<\/strong>.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Contributor permissions in <a href=\"https:\/\/ai.azure.com\" target=\"_blank\" rel=\"noopener\">Azure AI Foundry<\/a>.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code>homebrew<\/code> or <code>npm<\/code> for installing the CLI or VS Code with <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=openai.chatgpt\">Codex extension<\/a>.<\/span><\/li>\n<\/ul>\n<table style=\"width: 100%;\">\n<thead>\n<tr>\n<th style=\"width: 33.665%;\"><strong><span style=\"font-family: verdana, geneva, sans-serif;\">Requirement<\/span><\/strong><\/th>\n<th style=\"width: 145.107%;\"><strong><span style=\"font-family: verdana, geneva, sans-serif;\">Details<\/span><\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Operating systems<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">macOS 12+, Ubuntu 20.04+\/Debian 10+, or Windows 11 via WSL2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Git (optional, recommended)<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">2.23+ for built-in PR helpers<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">RAM<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">4-GB minimum (8-GB recommended)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step\u00a01 &#8211; Deploy a Codex model in Azure\u00a0AI\u00a0Foundry<\/span><\/h3>\n<ol>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Go to Azure AI Foundry @ <code><a href=\"https:\/\/ai.azure.com\">ai.azure.com<\/a><\/code> and create a new project.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Select a reasoning model such as <a href=\"https:\/\/devblogs.microsoft.com\/foundry\/codex-mini-fast-scalable-code-generation-for-the-cli-era\/\" target=\"_blank\" rel=\"noopener\"><code>codex-mini<\/code><\/a>, <code>gpt-5<\/code>, or <code>gpt-5-mini<\/code>.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Click <strong>Deploy<\/strong>, choose a name, and wait about two minutes.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Copy the <strong>Endpoint URL<\/strong> and <strong>API key<\/strong>.<\/span><\/li>\n<\/ol>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step\u00a02 &#8211; Install and Run the Codex CLI<\/span><\/h3>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">brew install codex\r\ncodex --version # verify installation<\/code><\/pre>\n<\/div>\n<\/div>\n<table style=\"width: 100%;\">\n<thead>\n<tr>\n<th style=\"width: 33.665%;\"><strong><span style=\"font-family: verdana, geneva, sans-serif;\">Command<\/span><\/strong><\/th>\n<th style=\"width: 145.107%;\"><strong><span style=\"font-family: verdana, geneva, sans-serif;\">Purpose<\/span><\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: Consolas, Monaco, monospace;\">codex<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Interactive TUI<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: Consolas, Monaco, monospace;\">codex &#8220;&#8230;&#8221;<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Initial prompt for interactive TUI<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.665%;\"><span style=\"font-family: Consolas, Monaco, monospace;\">codex exec &#8220;&#8230;&#8221;<\/span><\/td>\n<td style=\"width: 145.107%;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Non-interactive &#8220;automation mode&#8221;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step 3a &#8211; Configure <code>~\/.codex\/config.toml<\/code><\/span><\/h3>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Create a TOML configuration file to tell Codex how to connect to Azure and other tools. Here is an example that configures both Azure OpenAI and an MCP server for Microsoft Learn documentation.<\/span><\/p>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-toml\"><code class=\"language-toml\"># Set the default model and provider\r\nmodel = \"gpt-5\" \r\nmodel_provider = \"azure\"\r\npreferred_auth_method = \"apikey\"\r\n\r\n# Configure the Azure provider\r\n[model_providers.azure]\r\nname = \"Azure\"\r\n# Make sure you set the appropriate subdomain for this URL.\r\nbase_url = \"https:\/\/YOUR_PROJECT_NAME.openai.azure.com\/openai\"\r\nenv_key = \"AZURE_OPENAI_API_KEY\"\r\nquery_params = { api-version = \"2025-04-01-preview\" }\r\nwire_api = \"responses\"\r\nmodel_reasoning_effort = \"high\"\r\n\r\n# Example of configuring an MCP server for Playwright\r\n<\/code>[<span class=\"pl-en\">mcp_servers<\/span>.<span class=\"pl-en\">playwright<\/span>] <span class=\"pl-smi\">command<\/span> = <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>npx<span class=\"pl-pds\">\"<\/span><\/span> <span class=\"pl-smi\">args<\/span> = [<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>@playwright\/mcp@latest<span class=\"pl-pds\">\"<\/span><\/span>]<code class=\"language-toml\">\r\n<\/code><\/pre>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\"># Linux, macOS, or WSL \r\nexport AZURE_OPENAI_API_KEY=\"&lt;your-api-key&gt;\"<\/code><\/pre>\n<\/div>\n<\/div>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step 3b &#8211; Use Codex from the VS Code extension<\/span><\/h3>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">You can also access Codex directly inside Visual Studio Code using the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=openai.chatgpt\">OpenAI ChatGPT<\/a> extension.<\/span><\/p>\n<ol>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Install the extension from the VS Code Marketplace: <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=openai.chatgpt\">OpenAI Codex<\/a>.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">When using <em>Azure OpenAI<\/em> (not ChatGPT), you must use this temporary workaround. First, ensure your configuration file has this entry:<\/span>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-toml\"><code class=\"language-toml\"># ~\/.codex\/config.toml\r\npreferred_auth_method = \"apikey\"<\/code><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Export both API keys in your terminal, then launch VS Code from the same terminal (VS Code cannot be launched directly &#8211; it must inherit these environment variables from the command line):<\/span>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-default\"><code class=\"language-default\"># macOS\/Linux\/WSL\r\nexport OPENAI_API_KEY=\"your-azure-api-key-here\"\r\nexport AZURE_OPENAI_API_KEY=\"your-azure-api-key-here\"\r\ncode .  # Launch VS Code from terminal<\/code><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><span style=\"font-family: verdana, geneva, sans-serif;\">With the environment and configuration set, use the extension&#8217;s chat or inline actions to ask Codex to generate, refactor, or explain code &#8211; it will route through your Azure OpenAI deployment as configured (ensure you are not signed in to ChatGPT)<\/span><\/span><a href=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-vscode.png\"><img decoding=\"async\" class=\"alignnone wp-image-1357 size-full\" src=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-vscode.png\" alt=\"codex vscode image\" width=\"613\" height=\"283\" srcset=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-vscode.png 613w, https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-vscode-300x138.png 300w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/><\/a><\/li>\n<\/ol>\n<div class=\"notice notice-info\"><span style=\"font-family: verdana, geneva, sans-serif;\"><strong>\nNote (temporary):<\/strong> This environment variable workaround is required due to an open bug affecting the extension + Azure OpenAI flow. See the maintainers&#8217; update <a href=\"https:\/\/github.com\/openai\/codex\/issues\/2813#issuecomment-3233918550\">here<\/a>. OpenAI is working on a fix to make this work via <code>config.toml and settings.json<\/code> &#8211; without requiring the environment variable workaround above.<\/span><\/div>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step 4 &#8211; Giving Codex Memory with AGENTS.md<\/span><\/h3>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">You can give Codex extra instructions and guidance using <code>AGENTS.md<\/code> files. Codex looks for <code>AGENTS.md<\/code> files in the following places and merges them top-down, giving it context about your personal preferences, project-specific details, and the current task:<\/span><\/p>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code>~\/.codex\/AGENTS.md<\/code> &#8211; personal global guidance.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code>AGENTS.md<\/code> at your repository&#8217;s root &#8211; shared project notes.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code>AGENTS.md<\/code> in the current working directory &#8211; sub-folder\/feature specifics.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">For example, to help Codex understand how to write code for Azure AI Foundry Agents, you could create an <code>AGENTS.md<\/code> in your project root with the following content, derived from the Azure AI Agents SDK documentation:<\/span><\/p>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-markdown\"><code class=\"language-markdown\"># Instructions for working with Azure AI Foundry Agents\r\n\r\nYou are an expert in the Azure AI Agents client library for Python.\r\n\r\n## Key Concepts\r\n\r\n- **Client Initialization**: Always start by creating an `AIProjectClient` or `AgentsClient`. The recommended way is via `AIProjectClient`.\r\n- **Authentication**: Use `DefaultAzureCredential` from `azure.identity`.\r\n- **Agent Creation**: Use `agents_client.create_agent()`. Key parameters are `model`, `name`, and `instructions`.\r\n- **Tools**: Agents use tools to perform actions like file search, code interpretation, or function calls.\r\n  - To use tools, they must be passed to `create_agent` via the `tools` and `tool_resources` parameters or a `toolset`.\r\n  - Example: `file_search_tool = FileSearchTool(vector_store_ids=[...])`\r\n  - Example: `code_interpreter = CodeInterpreterTool(file_ids=[...])`\r\n  - Example: `functions = FunctionTool(user_functions)`\r\n\r\n## Example: Creating a basic agent\r\n\r\n```python\r\nimport os\r\nfrom azure.ai.projects import AIProjectClient\r\nfrom azure.identity import DefaultAzureCredential\r\n\r\n# 1. Create Project Client\r\nproject_client = AIProjectClient(\r\n    endpoint=os.environ[\"PROJECT_ENDPOINT\"],\r\n    credential=DefaultAzureCredential(),\r\n)\r\n\r\n# 2. Get Agents Client\r\nwith project_client:\r\n    agents_client = project_client.agents\r\n\r\n    # 3. Create Agent\r\n    agent = agents_client.create_agent(\r\n        model=os.environ[\"MODEL_DEPLOYMENT_NAME\"],\r\n        name=\"my-helpful-agent\",\r\n        instructions=\"You are a helpful agent that can answer questions.\",\r\n    )\r\n    print(f\"Created agent with ID: {agent.id}\")\r\n```<\/code><\/pre>\n<\/div>\n<\/div>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step 5 &#8211; Explore with your coding agent<\/span><\/h3>\n<div class=\"code-block\">\n<div class=\"formatted-code-block-internal-container\">\n<pre><span style=\"font-family: verdana, geneva, sans-serif;\"><code class=\"code-container\">codex \"write a python script to create an Azure AI Agent with file search capabilities\"\r\n<\/code><\/span><\/pre>\n<\/div>\n<\/div>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code># generate a unit test for src\/utils\/date.ts<\/code><\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\"><code># refactor this agent to use the Code Interpreter tool instead<\/code><\/span><\/li>\n<\/ul>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step\u00a06 &#8211; Run Codex in GitHub Actions<\/span><\/h3>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-1051\" src=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1-300x200.png\" alt=\"codex blog featured image image\" width=\"300\" height=\"200\" srcset=\"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1-300x200.png 300w, https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1-1024x683.png 1024w, https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1-768x512.png 768w, https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-content\/uploads\/sites\/83\/2025\/06\/codex-blog-featured-image-1.png 1536w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">Codex can execute as part of your CI pipeline. Store your API key in the <\/span><span style=\"font-family: verdana, geneva, sans-serif;\">repository\u2019s secret store as <code>AZURE_OPENAI_KEY<\/code> and add a job like this to automatically update your changelog before a release:<\/span><\/p>\n<div class=\"code-block\">\n<div class=\"code-block-decoration header-formatted gds-title-s\">\n<pre class=\"prettyprint language-yaml\"><code class=\"language-yaml\">jobs:\r\n  update_changelog:\r\n    runs-on: ubuntu-latest\r\n    steps:\r\n      - uses: actions\/checkout@v4\r\n      - name: Update changelog via Codex\r\n        run: |\r\n          npm install -g @openai\/codex\r\n          export AZURE_OPENAI_API_KEY=\"${{ secrets.AZURE_OPENAI_KEY }}\" \r\n          codex -p azure exec --full-auto \"update CHANGELOG for next release\"\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Step\u00a07 &#8211; Explore more agents with <a href=\"https:\/\/asyncloom.com\">AsyncLoom<\/a><\/span><\/h3>\n<ul>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Browse detailed docs and benchmarks for other Azure-hosted agents.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Create repo-ready configuration guides with one click.<\/span><\/li>\n<li><span style=\"font-family: verdana, geneva, sans-serif;\">Experiment with GitHub Copilot Coding Agent, Cognition Devin, SRE Agent, and others.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Troubleshooting<\/span><\/h3>\n<p>&nbsp;<\/p>\n<table style=\"height: 236px; width: 100%;\">\n<thead>\n<tr style=\"height: 24px;\">\n<th style=\"width: 33.665%; height: 24px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Symptom<\/span><\/th>\n<th style=\"width: 145.107%; height: 24px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Fix<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 81px;\">\n<td style=\"width: 33.665%; height: 81px;\"><span style=\"font-family: verdana, geneva, sans-serif;\"><code>401 Unauthorized<\/code> or <code>403 Forbidden<\/code><\/span><\/td>\n<td style=\"width: 145.107%; height: 81px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Export your <code>AZURE_OPENAI_API_KEY<\/code> environment variable correctly.\nConfirm that your key has <em>project\/deployment<\/em> access.<\/span><\/td>\n<\/tr>\n<tr style=\"height: 111px;\">\n<td style=\"width: 33.665%; height: 111px;\"><span style=\"font-family: verdana, geneva, sans-serif;\"><code>ENOTFOUND<\/code>, DNS error, or <code>404 Not\u00a0Found<\/code><\/span><\/td>\n<td style=\"width: 145.107%; height: 111px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Verify <code>base_url<\/code> in <code>config.toml<\/code> uses your resource name and correct domain, e.g.\n<code>base_url = \"https:\/\/&lt;your-resource&gt;.openai.azure.com\/openai\"<\/code>.\n<\/span><\/td>\n<\/tr>\n<tr style=\"height: 10px;\">\n<td style=\"width: 33.665%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">CLI ignores Azure settings<\/span><\/td>\n<td style=\"width: 145.107%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Open <code>~\/.codex\/config.toml<\/code> and ensure:\n<\/span><\/p>\n<ul>\n<li><code>model_provider = \"azure\"<\/code> is set.<\/li>\n<li>The <code>[model_providers.azure]<\/code> section exists.<\/li>\n<li><code>env_key = \"AZURE_OPENAI_API_KEY\"<\/code> matches your exported variable.<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr style=\"height: 10px;\">\n<td style=\"width: 33.665%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">In Codex, you get a warning that &#8220;codex-mini&#8221; is not in the list of available models for provider &#8220;azure&#8221;<\/span><\/td>\n<td style=\"width: 145.107%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">This is a known issue, and we have a PR in progress to address this. Ignore this warning and proceed with codex-cli tasks.<\/span><\/td>\n<\/tr>\n<tr style=\"height: 10px;\">\n<td style=\"width: 33.665%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">VS Code extension not using Azure key<\/span><\/td>\n<td style=\"width: 145.107%; height: 10px;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Apply the temporary workaround above: set <code>preferred_auth_method = \"apikey\"<\/code> in <code>config.toml<\/code> and export <code>OPENAI_API_KEY<\/code> and <code>AZURE_OPENAI_API_KEY<\/code> to the same Azure key. See the <a href=\"https:\/\/github.com\/openai\/codex\/issues\/2813#issuecomment-3233918550\">maintainers\u2019 note<\/a>.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-family: verdana, geneva, sans-serif;\">Conclusion<\/span><\/h3>\n<p><span style=\"font-family: verdana, geneva, sans-serif;\">In just a few minutes you can connect an AI coding agent to your Azure tenant,<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">keep intellectual property secure, and accelerate software delivery. Combine<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">Codex CLI, Codex in VSCode, and GitHub Actions to build a flexible<\/span>\n<span style=\"font-family: verdana, geneva, sans-serif;\">AI-powered engineering workflow. Give it a try and share what you create.<\/span><\/p>\n<hr \/>\n<p style=\"font-size: 0.9em;\"><span style=\"font-family: verdana, geneva, sans-serif;\">Questions or feedback? Drop a comment below<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction You can now enjoy the same Codex experience in CLI or VS Code with Azure OpenAI support. We&#8217;ve contributed the following five pull requests to make this possible, giving you the familiar Codex functionality from ChatGPT while running securely on Azure: PR\u00a0#769 PR\u00a0#1324 PR\u00a0#1321 PR\u00a0#1778 (awaiting merge &#8211; Entra\u00a0ID token-based authentication related to PR\u00a0#92) [&hellip;]<\/p>\n","protected":false},"author":172657,"featured_media":1051,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[35,37,1,38,20],"tags":[2,74,79,80,82,81],"class_list":["post-1041","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-agents","category-ai-foundry","category-azure","category-app-development","category-developer-productivity","tag-azure","tag-azure-openai","tag-codex","tag-codex-mini","tag-coding-agent","tag-openai"],"acf":[],"blog_post_summary":"<p>Introduction You can now enjoy the same Codex experience in CLI or VS Code with Azure OpenAI support. We&#8217;ve contributed the following five pull requests to make this possible, giving you the familiar Codex functionality from ChatGPT while running securely on Azure: PR\u00a0#769 PR\u00a0#1324 PR\u00a0#1321 PR\u00a0#1778 (awaiting merge &#8211; Entra\u00a0ID token-based authentication related to PR\u00a0#92) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/posts\/1041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/users\/172657"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/comments?post=1041"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/posts\/1041\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/media\/1051"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/media?parent=1041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/categories?post=1041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/all-things-azure\/wp-json\/wp\/v2\/tags?post=1041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}