-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: main
Are you sure you want to change the base?
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. |
Thank you for testing with Azure OpenAI and providing your feedback. I’ve escalated this internally. We are currently experiencing capacity issues due to a spike in demand - both from new users and, more importantly, from migrating existing 4o token consumers to o4-mini or o3. As we increase capacity, you should see fewer timeouts and less general degradation. |
@thegovind Have you implement retry mechanism in this pull request? |
Is there something stopping this from being merged? Not sure how this process works but I also have several people waiting on this. |
I’ve received all the necessary approvals (@theabhinavdas - could you also officially approve the PR as indicated here?), and several of you have tested and verified it. At this point, it’s really up to OpenAI, and specifically @tibo-openai. |
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
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.