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 Astra for the most demanding workflows, GPT-6.1 Sol for near-Astra performance at a lower cost, GPT-6.1 Terra as a fast, efficient choice for writing, visual understanding and computer use, and Luna for focused, repeatable tasks.
Last verified 8 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.
GPT-6.1 Terra requires Codex CLI 0.159.0 or later.
Terminalcodex -m gpt-6.1-terra - Step 8.
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 users signed in with ChatGPT on October 14, 2026; the OpenAI API and Codex sessions authenticated with an API key are not affected.
- For Codex with ChatGPT sign-in, the replacement is GPT-6.1 Sol (gpt-6.1-sol) on Plus, Pro, Business, Enterprise and Edu plans when available, and GPT-6 Luna (gpt-6-luna) in the desktop app on Free and Go plans when available. In Enterprise and Edu, an administrator must enable Luna first.
- gpt-6-sol is named on the Codex models page as the replacement for the retired gpt-5.4 when available to your plan and client.
- With API-key authentication, model availability follows your API organization and project, usage is billed at standard API rates, and some features that rely on ChatGPT workspace access or cloud services are limited or unavailable.
- GPT-6.1 Sol uses a default context window of 500,000 tokens in Codex and ChatGPT Work.
- Current Codex releases do not support wire_api = "chat" or a Chat Completions-only endpoint for custom providers; use a compatible Responses API endpoint.
- Codex docs at developers.openai.com/codex now redirect to learn.chatgpt.com/docs.
More setup guides
Same tool, other providers
Related reading
- Droid vs Codex (2026): Factory vs OpenAI for Terminal Coding AgentsFactory Droid vs OpenAI Codex compared on models, pricing, headless CI, multi-agent work, extensibility and openness, with a clear recommendation for each kind of developer.
- Codex CLI 0.171: codex exec --remote, Workspace On by DefaultCodex CLI 0.171.0 adds codex exec --remote to run headless sessions on an existing app server, turns on the TUI workspace by default and picks GPT-6.2 Sol.
- GPT-6.2 Astra and Sol: Pricing, Benchmarks and What to SwitchGPT-6.2 Astra costs $8/$40 per MTok (20% under GPT-6 Astra), Sol stays $2/$10. Vendor-reported benchmarks, cache rates, Codex setup and who should switch.
- Codex CLI 0.169: codex exec Trust, Side Chats and Model ProvidersCodex CLI 0.169.0 keeps project config and MCP servers off in untrusted directories under codex exec, adds --trust, side-chat tabs and a model provider picker.
- Codex Training Setting Re-Enabled? Two Switches to CheckDevelopers report Codex model training turning itself back on. What OpenAI documents, the second "Include environments" switch most people miss, and a five-minute check.
- OpenAI Pando: The Git Backend Built for Codex-Scale PushesOpenAI built Pando, a Git-compatible backend, after Codex flooded its monorepo with pushes. What it changed, the trade-offs, and what it means for your agent fleet.
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 Astra for the most demanding workflows, GPT-6.1 Sol for near-Astra performance at a lower cost, GPT-6.1 Terra as a fast, efficient choice for writing, visual understanding and computer use, and Luna for focused, repeatable tasks.
Which OpenAI model ids work in Codex CLI?
The official docs read for this guide list gpt-6-astra, gpt-6.1-sol, gpt-6.1-terra, gpt-6-luna, gpt-6-sol 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 November 8, 2026.
Sources
Last verified against 4 official pages.
- raw.githubusercontent.comhttps://raw.githubusercontent.com/openai/codex/main/README.md
- learn.chatgpt.comhttps://learn.chatgpt.com/docs/auth.md
- learn.chatgpt.comhttps://learn.chatgpt.com/docs/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.