Repository navigation
feat(ts): provider‑specific API‑key discovery and clearer Azure guidance - #1324
Merged
Merged
Conversation
Clarifies the instructions for creating an Azure OpenAI API key, directing users to the Azure AI Foundry portal and specifying the correct environment variable name.
Adds support for retrieving API keys from environment variables for providers other than OpenAI. This allows users to use alternative language models without relying on the OpenAI authentication flow. It ensures the credit redemption logic is only attempted for OpenAI providers.
Adds support for retrieving API keys from environment variables for providers other than OpenAI. This allows users to use alternative language models without relying on the OpenAI authentication flow. It ensures the credit redemption logic is only attempted for OpenAI providers.
fouad-openai
approved these changes
Jun 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the Codex CLI authentication flow so that non-OpenAI providers (for example azure, or any future addition) can supply their API key through a dedicated environment variable without triggering the OpenAI login flow.
Key behaviours introduced:
provider !== "openai"the CLI consultssrc/utils/providers.tsto locate the correct environment variable (AZURE_OPENAI_API_KEY,GEMINI_API_KEY, and so on) before considering any interactive login.--free) and PKCE login now run only when the provider is OpenAI, eliminating unwanted browser prompts for Azure and others.OPENAI_API_KEYso legacy scripts continue to operate unchanged.Example
config.json{ "model": "codex-mini", "provider": "azure", "providers": { "azure": { "name": "AzureOpenAI", "baseURL": "https://ai-<project-name>.openai.azure.com/openai", "envKey": "AZURE_OPENAI_API_KEY" } }, "history": { "maxSize": 1000, "saveHistory": true, "sensitivePatterns": [] } }With this file in
~/.codex/config.json, a single command line is enough:No browser window opens, and the CLI works in entirely non-interactive mode.
Rationale
The new flow enables Codex to run asynchronously in sandboxed environments such as GitHub Actions pipelines. By passing
--provider azure(or setting it inconfig.json) and exporting the correct key, CI/CD jobs can invoke Codex without any ChatGPT-style login or PKCE round-trip. This unlocks fully automated testing and deployment scenarios.What’s changed
codex-cli/src/cli.tsxproviders, adds early provider-specific key lookup, gates--freeredemption, rewrites help text.src/utils/providers.tsHow to test
Expected outcomes:
OPENAI_API_KEYfor backward compatibility.Checklist
Related work
I have read the CLA Document and I hereby sign the CLA.