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 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.
- GPT-6.1 Terra: $1/$5 Pricing, Benchmarks, and When to Pick ItGPT-6.1 Terra is OpenAI's new $1/$5 per million token model: 50.3% on Terminal-Bench 4.0 (vendor-reported), half Sol's price, and who should route to it.
- Codex CLI 0.164: /presets and Inline /model FlagsCodex CLI 0.164.0 adds ten /presets slots, inline /model and /permissions arguments, and credential masking for remote commands. What to try and what to check.
- Codex Reset: Banked vs Automatic vs Paid, and When to Use EachCodex has three kinds of usage reset - banked, automatic and paid - and they move your weekly refresh date in different ways. What OpenAI documents, the 80% rule, and what to do Monday.
- OpenAI Models on Google Cloud: What Changes for DevelopersOpenAI and Google Cloud put GPT-6 Astra, GPT-6.1 Sol and GPT-6 Luna into Model Garden in private preview, with Codex pointed at Gemini inference. What is live, what is "coming soon", and what to do before general availability.
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.