-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat: add azure openai support #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
That was fast! Was looking for this. Thanks |
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
Hi, I tried running this PR, but Codex still throws the error “Missing OpenAI API key.” even though I’ve set the following environment variables: It looks like we might also need to update cli.tsx. |
@thegovind Adding tests will also help. |
@junseinagao Thanks for testing. I’ve only added support for Entra ID, so you’ll need to run |
Agree, working on it. |
Thanks for this, can we make it work with non-Entra ID Azure OpenAI as well, i.e.: Just the AZURE_OPENAI_KEY and stuff? Would be much more helpful! Thanks! |
Since you're working on this, can you also take a look at this issue above - so that a TON of people will benefit? Much appreciated. |
Would it be possible to build this in a way that doesn't depend on "@azure/identity"? |
@adhishthite @tibo-openai @junseinagao @theabhinavdas @alioftech and others following this - Thanks for your patience! I’ll be pushing more updates soon, but we need to wait for our Azure OpenAI Inference team (@YunsongB) to update the underlying APIs before everything works end-to-end. The latest API version from our side needs to reach parity with OpenAI (with If you try to use the most recent spec ( Specifically, You could add a conditional for AOAI here, but that’s probably unnecessary since the update is expected very shortly. So in short: let’s not put the cart before the horse 😄 I’ll follow up with the commits as soon as the updated APIs are live - likely next week. |
This is great, win win |
Nice! |
Amazing, keeping an eye on this! |
@thegovind Any timeline for the update to the Azure openai inference api? If the release is delayed, it might be wise to add the conditional for AOAI and get this merged. You can always come back and remove it. |
Can we get this in? OpenAI org verification wants my passport, no thank you, I will run this via Azure |
/compact didn't work for me I had to make some changes. Can I contribute somehow? @thegovind |
Yes, please go ahead-thank you. As for conflicts, I’ve resolved merge conflicts countless times now. I’ll do it one last time once I know that OpenAI and @tibo-openai intend to support Azure OpenAI. Frankly, it’s starting to look like they don’t, which goes against the spirit of open source. |
Create a new fork similar to open-codex if they're unresponsive; there's no need to handle it that way. :) |
I think that they don't want to add the azure/identity dependency @thegovind |
@heymaaz @bsormagec @tibo-openai |
@tibo-openai can we get a response on this? many of us are waiting for this to be implemented so that we can use the official release and not create a separate fork. |
In the openai-python library, azure-identity is currently listed only as a dev dependency. Could an alternative approach work here to avoid adding it as a mandatory dependency? For instance:
This approach seems like it could provide the needed Azure AD authentication flexibility without imposing the dependency on all users of the library. Would you be open to a solution like this? |
@seanabreau - I’m happy to refactor to highlight azure-identity in an example (similar to official SDK), but first I need clarity on one point: will OpenAI and @tibo-openai support Azure OpenAI as a target for Codex? Code generation with Codex and GitHub Copilot was our first proof of PMF for transformer models, well before ChatGPT captured the spotlight. Building on that collaborative ethos, now extended to open-source contributions, I trust OpenAI will guide Codex so it remains valuable to developers everywhere, including those on Azure OpenAI. Frankly, with Claude and Gemini gaining ground, our relevance and usage are no longer where they once were with Dev audience. Ensuring Codex works on Azure OpenAI would be a decisive step toward regaining that momentum. |
One question. It seems a bit of delay for this. Any idea why? It seems they are going directly to 2025-05-01: Azure/azure-rest-api-specs#34051? |
Do we know if OpenAI will give any response about this support ? Is there a way to get it working today using the API key method or not even that work ? |
You can open the fork that was made for this pull request and download/run through there. I was able to successfully do it, I can't remember how. I think Manus told me how. |
Yes, my fork will remain available for use with Azure OpenAI. Instructions are above. You'll need to set |
My question was more until this is not merged is there some environment variables that I can set tp be able to use it with azureopenai and an api key from main ? |
You might want to try using the litellm proxy and set the While we’ll likely need to be patient for the PR to be merged (it currently has conflicts with the |
With the changes on this branch, the AOAI settings are not applied when asking to explain the current command (press |
Everyone! Let's get this rolling! |
below are the steps I took to get the fork from thegovind working (these may or may not all be required, but, it is what worked for me):
and set the env vars:
is there any real reason this pr hasn't been merged? |
hey @thegovind thanks for this contribution! we landed a PR to add support for multiple providers a ~week ago and would be great if you could use the latest as starting point, here's providers.ts as a reference point |
Thank you, @fouad-openai! Working on it now. |
Hi @fouad-openai @tibo-openai I'm starting a separate PR (please leave this one open for now) - #769 - as the provider approach is quite different from what Codex was released with. Now, I have 7 tests in main that are failing. I'm not sure if others are seeing this as well (this is on Windows, but I tested in both bash and pwsh). It would be good to resolve this first. I've tested my changes with Azure OpenAI locally, and they are working fine. |
## Summary This PR introduces support for Azure OpenAI as a provider within the Codex CLI. Users can now configure the tool to leverage their Azure OpenAI deployments by specifying `"azure"` as the provider in `config.json` and setting the corresponding `AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_API_VERSION` environment variables. This functionality is added alongside the existing provider options (OpenAI, OpenRouter, etc.). Related to #92 **Note:** This PR is currently in **Draft** status because tests on the `main` branch are failing. It will be marked as ready for review once the `main` branch is stable and tests are passing. --- ## What’s Changed - **Configuration (`config.ts`, `providers.ts`, `README.md`):** - Added `"azure"` to the supported `providers` list in `providers.ts`, specifying its name, default base URL structure, and environment variable key (`AZURE_OPENAI_API_KEY`). - Defined the `AZURE_OPENAI_API_VERSION` environment variable in `config.ts` with a default value (`2025-03-01-preview`). - Updated `README.md` to: - Include "azure" in the list of providers. - Add a configuration section for Azure OpenAI, detailing the required environment variables (`AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_API_VERSION`) with examples. - **Client Instantiation (`terminal-chat.tsx`, `singlepass-cli-app.tsx`, `agent-loop.ts`, `compact-summary.ts`, `model-utils.ts`):** - Modified various components and utility functions where the OpenAI client is initialized. - Added conditional logic to check if the configured `provider` is `"azure"`. - If the provider is Azure, the `AzureOpenAI` client from the `openai` package is instantiated, using the configured `baseURL`, `apiKey` (from `AZURE_OPENAI_API_KEY`), and `apiVersion` (from `AZURE_OPENAI_API_VERSION`). - Otherwise, the standard `OpenAI` client is instantiated as before. - **Dependencies:** - Relies on the `openai` package's built-in support for `AzureOpenAI`. No *new* external dependencies were added specifically for this Azure implementation beyond the `openai` package itself. --- ## How to Test *This has been tested locally and confirmed working with Azure OpenAI.* 1. **Configure `config.json`:** Ensure your `~/.codex/config.json` (or project-specific config) includes Azure and sets it as the active provider: ```json { "providers": { // ... other providers "azure": { "name": "AzureOpenAI", "baseURL": "https://YOUR_RESOURCE_NAME.openai.azure.com", // Replace with your Azure endpoint "envKey": "AZURE_OPENAI_API_KEY" } }, "provider": "azure", // Set Azure as the active provider "model": "o4-mini" // Use your Azure deployment name here // ... other config settings } ``` 2. **Set up Environment Variables:** ```bash # Set the API Key for your Azure OpenAI resource export AZURE_OPENAI_API_KEY="your-azure-api-key-here" # Set the API Version (Optional - defaults to `2025-03-01-preview` if not set) # Ensure this version is supported by your Azure deployment and endpoint export AZURE_OPENAI_API_VERSION="2025-03-01-preview" ``` 3. **Get the Codex CLI by building from this PR branch:** Clone your fork, checkout this branch (`feat/azure-openai`), navigate to `codex-cli`, and build: ```bash # cd /path/to/your/fork/codex git checkout feat/azure-openai # Or your branch name cd codex-cli corepack enable pnpm install pnpm build ``` 4. **Invoke Codex:** Run the locally built CLI using `node` from the `codex-cli` directory: ```bash node ./dist/cli.js "Explain the purpose of this PR" ``` *(Alternatively, if you ran `pnpm link` after building, you can use `codex "Explain the purpose of this PR"` from anywhere)*. 5. **Verify:** Confirm that the command executes successfully and interacts with your configured Azure OpenAI deployment. --- ## Tests - [x] Tested locally against an Azure OpenAI deployment using API Key authentication. Basic commands and interactions confirmed working. --- ## Checklist - [x] Added Azure provider details to configuration files (`providers.ts`, `config.ts`). - [x] Implemented conditional `AzureOpenAI` client initialization based on provider setting. - [x] Ensured `apiVersion` is passed correctly to the Azure client. - [x] Updated `README.md` with Azure OpenAI setup instructions. - [x] Manually tested core functionality against a live Azure OpenAI endpoint. - [x] Add/update automated tests for the Azure code path (pending `main` stability). cc @theabhinavdas @nikodem-wrona @fouad-openai @tibo-openai (adjust as needed) --- I have read the CLA Document and I hereby sign the CLA
closing now that #769 merged |
Summary
Adds optional Azure OpenAI support alongside the existing OpenAI flow. When
AZURE_OPENAI_ENDPOINT
(plus related env vars) is set, Codex will authenticate via Entra ID and call the Responses API against your Azure OpenAI deployments. Otherwise it falls back to the standardOPENAI_API_KEY
path.Closes #11 #174
What’s Changed
model‑utils.ts
AZURE_OPENAI_ENDPOINT
; if present, uses@azure/identity
’sDefaultAzureCredential
and the SDK’sAzureOpenAI
client to list deployments via Responses API.OPENAI_API_KEY
flow or default model list on errors.agent-loop.ts
config.ts
:AZURE_OPENAI_ENDPOINT
AZURE_OPENAI_API_VERSION
AZURE_OPENAI_DEPLOYMENT
(optional)AZURE_OPENAI_API_KEY
(fallback)cli.tsx
now errors if neitherOPENAI_API_KEY
norAZURE_OPENAI_ENDPOINT
is configured.az login
and Azure env‑var setup.@azure/identity
and bumpedopenai
to includeAzureOpenAI
support.How to Test
Deploy your model
o4‑mini
oro3
to your Azure OpenAI resource.Set up env vars
Get the Codex CLI by building from your PR branch
Clone your specific PR branch and build the CLI:
Invoke Codex
Run the locally built CLI using
node
from thecodex-cli
directory:node ./dist/cli.js "explain this function"
(Alternatively, if you ran
pnpm link
in the previous step, you can simply usecodex "explain this function"
from anywhere).Tests
Update default API version to2025-04-01-preview
once it’s available in Azure OpenAI(Note: Temporary Conditional logic added for Azure OpenAI will be removed in another PR)
Checklist
@azure/identity
, bumpedopenai
dependencycc @theabhinavdas @nikodem-wrona for SDK review.