Setup guide - From OpenAI and Codex CLI docs
Use OpenAI in Codex CLI
Codex CLI is OpenAI's own coding agent and uses OpenAI models natively. You sign in with ChatGPT (subscription) or an OpenAI API key (usage-based), then pick a model with --model or in config.toml. OpenAI's Codex docs recommend gpt-6.1-sol for complex coding and gpt-6-luna for focused, repeatable tasks.
Last verified 7 steps4 official sources
Steps
- Step 1.
Install Codex CLI (Mac or Linux installer, or npm / Homebrew).
Terminalcurl -fsSL https://chatgpt.com/codex/install.sh | sh # or npm install -g @openai/codex # or brew install --cask codex - Step 2.
Option A, subscription access: run codex login and complete the browser flow (Sign in with ChatGPT).
Terminalcodex login - Step 3.
Option B, usage-based access: pipe an OpenAI API key (from https://platform.openai.com/api-keys) to codex login through stdin.
Snippetprintenv OPENAI_API_KEY | codex login --with-api-key - Step 4.
Check which authentication method is active.
Terminalcodex login status - Step 5.
Choose a model at launch with --model (or -m), or with /model inside an interactive session.
Terminalcodex --model gpt-6.1-sol - Step 6.
Non-interactive runs take the same option.
Terminalcodex exec -m gpt-6.1-sol "Review the current changes" - Step 7.
Set a default model in config.toml (shared by the ChatGPT desktop app, Codex CLI and IDE extension).
TOMLmodel = "gpt-6.1-sol"
Caveats
- GPT-5.5 retired from Codex for ChatGPT sign-in on October 14, 2026; it remains available through the OpenAI API and in Codex sessions authenticated with an API key.
- With ChatGPT sign-in, GPT-6.1 Sol rollout covers Plus, Pro, Business, Enterprise and Edu; Free and Go are not included at launch, and Enterprise/Edu admins must enable it.
- With API-key authentication, model availability follows your API organization and project and is billed at standard API rates; some ChatGPT workspace and cloud features are limited or unavailable.
- gpt-6-astra is listed on the OpenAI API model catalog; the Codex models page names Astra in its guidance but its explicit config examples use gpt-6.1-sol and gpt-6-luna.
- Current Codex releases do not support wire_api = "chat" or a Chat Completions-only endpoint for custom providers.
- Codex docs at developers.openai.com/codex now serve from learn.chatgpt.com/docs.
More setup guides
Same tool, other providers
Related reading
- Codex CLI 0.163: Instant Steering Is Now the DefaultCodex CLI 0.163.0 makes mid-response steering the default and adds searchable /config and a leader key. What changed and what to check before upgrading.
- Codex 'gpt-5.5 Model Is Not Supported' Error: The FixCodex says gpt-5.5 is not supported with a ChatGPT account because OpenAI retired it from ChatGPT sign-in on October 14. The fix and what still works.
- Codex CLI Background Daemon: How to Turn It OffCodex CLI starts a persistent, self-updating background daemon since 0.157.0. What it does, why it hit Hacker News and the reported workaround to turn it off.
- Codex CLI 0.162: Managed Worktrees and Pinned TasksCodex CLI 0.162 lets the agent create and list its own Git worktrees, adds pinned tasks and custom provider capability overrides. What to change this week.
- ChatGPT Free vs Go vs Plus After GPT-6: Which Model You GetFree and Go ($8) both get GPT-6 Luna in Chat. Plus ($20) is the cheapest plan with GPT-6 Sol and full Codex. What each ChatGPT plan buys now.
- ChatGPT Plus vs Claude Pro for Developers (October 2026)Both cost $20 a month. Plus meters Codex apart from chat and includes GPT-6 Astra; Claude Pro shares one pool with Claude Code. Which to pick.
FAQ
How do I use OpenAI in Codex CLI?
Codex CLI is OpenAI's own coding agent and uses OpenAI models natively. You sign in with ChatGPT (subscription) or an OpenAI API key (usage-based), then pick a model with --model or in config.toml. OpenAI's Codex docs recommend gpt-6.1-sol for complex coding and gpt-6-luna for focused, repeatable tasks.
Which OpenAI model ids work in Codex CLI?
The official docs read for this guide list gpt-6.1-sol, gpt-6-luna, gpt-6-sol, gpt-6-astra and gpt-5.5.
Is this an official OpenAI and Codex CLI setup?
The steps draw on both OpenAI's and Codex CLI's docs. It was last checked against 4 official pages on October 17, 2026.
Sources
Last verified against 4 official pages.
- raw.githubusercontent.comhttps://raw.githubusercontent.com/openai/codex/main/README.md
- developers.openai.comhttps://developers.openai.com/codex/auth.md
- developers.openai.comhttps://developers.openai.com/codex/models.md
- developers.openai.comhttps://developers.openai.com/api/docs/models
Newsletter
New models, set up the day they ship
One email per week. New model releases, the coding tools that support them and how to wire them up.