AI API Keys 8 min read
Codex CLI: Install, Sign In, API Keys and Usage Limits
How to install and update Codex CLI, sign in, control what the agent may do, use its main commands, connect a custom provider and read the usage limits on ChatGPT Plus.
Key takeaways
- Codex CLI is OpenAI’s open source coding agent that runs in your terminal. Install it with a script, npm or Homebrew, then run
codexinside a project folder. - Sign in with a ChatGPT plan to use the plan’s allowance, or with an API key that is billed by use.
- On ChatGPT Plus, OpenAI estimates local messages per five-hour window by model, and weekly limits may also apply.
Codex CLI is the terminal version of OpenAI’s coding agent: it reads your project, edits files and runs commands from the same window you already work in. This guide covers installing and updating it, the first run, sign-in, permissions, commands, custom providers, usage limits and common errors. Commands and limits come from OpenAI’s documentation as of 29 November 2026. If you are looking for a key sold outside OpenAI, the third-party Codex API key is explained near the end.
What is Codex CLI?
Codex CLI is a coding agent that runs locally on your computer. According to OpenAI’s CLI documentation, it can inspect code, edit it, run commands and automate repeated work. You can use it interactively, or call it from scripts and pipelines with codex exec.
It is also open source. The openai/codex repository is written in Rust and licensed under Apache-2.0. The IDE extension and Codex cloud are not open source. The latest release we saw was 0.172.0, published on 24 November 2026.
How to install Codex CLI
Pick one of four install methods and then type codex to start. OpenAI’s repository lists macOS 12 or later, Ubuntu 20.04 or later, Debian 10 or later, or Windows 11 through WSL2, with at least 4 GB of RAM (8 GB recommended).
| Method | Command |
|---|---|
| macOS or Linux script | curl -fsSL https://chatgpt.com/codex/install.sh | sh |
| Windows PowerShell | powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" |
| npm | npm install -g @openai/codex |
| Homebrew | brew install --cask codex |
Windows and Linux notes
On Windows, Codex runs natively in PowerShell or inside WSL2, where you use the Linux installer from the WSL shell. OpenAI recommends Windows 11 and treats a recent, fully updated Windows 10 as best effort; the repository’s install page, mentioned above, names only the WSL2 route. Open a new PowerShell window before running the installer.
On Linux and WSL2, install bubblewrap first, because the sandbox depends on it. On Ubuntu or Debian that is sudo apt install bubblewrap.
How to update Codex CLI
Update Codex CLI the same way you installed it. Check your version first with codex --version.
- Script installs: run the same installer command again.
- npm:
npm install -g @openai/codex - Homebrew:
brew upgrade --cask codex - Built-in:
codex updateworks when your installed release supports self-update.
How to run Codex CLI for the first time
Open a project folder, run codex and choose how to sign in. Then describe the job in plain words, for example ask it to explain the project, make one focused change or find the cause of a bug.
- Commit your work in Git, so you have a checkpoint to return to. OpenAI advises one before and after each task.
- Run
/statusto see the active model, settings and token use. - Run
/initto create an AGENTS.md file with project instructions. - Review the changes with
/diffbefore you keep them.
Sign in with ChatGPT or an API key
Codex CLI accepts two main sign-in methods: a ChatGPT account for subscription access, or an API key for pay-by-use access. The README recommends signing in with ChatGPT to use Codex with Plus, Pro, Business, Edu or Enterprise plans.
| Question | ChatGPT sign-in | API key sign-in |
|---|---|---|
| How you start | codex login opens the browser |
printenv OPENAI_API_KEY | codex login --with-api-key |
| What pays for usage | Your plan’s allowance and any credits | Your OpenAI Platform account, at standard API rates |
| Cloud features | Required for Codex cloud | Limited or unavailable |
| Typical use | Daily work at your desk | Scripts and CI jobs |
On a machine without a browser, try the device code flow, codex login --device-auth, which OpenAI labels beta. codex login status shows the active method and codex logout clears it. Cached credentials may sit in plain text in ~/.codex/auth.json, so treat that file like a password and keep it out of Git.
Plan prices are covered in our ChatGPT pricing guide.
Approvals and sandbox settings
Two settings control what Codex may do: the sandbox limits what it can technically touch, and the approval policy decides when it must ask. By default network access is off.
- Auto: the usual recommendation in a version-controlled folder. Codex reads, edits and runs commands inside the working directory, and asks before editing outside it or using the network.
- Read-only: the recommendation for folders without version control. Switch at any time with
/permissions. - Flags:
--sandboxtakesread-only,workspace-writeordanger-full-access;--ask-for-approvaltakeson-requestornever. - Automatic review:
--approve-for-mesends eligible approval requests to a reviewer agent inside the workspace-write sandbox, which can add usage.
There is also --yolo, short for --dangerously-bypass-approvals-and-sandbox. It removes both safety layers and can destroy files or data. OpenAI marks it as not recommended and says to use it only inside an externally hardened environment, never on your everyday machine.
Codex CLI commands you will use most
Terminal commands start with codex, while slash commands are typed inside a session.
| Command | What it does |
|---|---|
codex exec "task" |
Runs one task without the interactive screen |
codex resume |
Continues an earlier session |
codex review |
Reviews uncommitted changes, a branch diff or a commit |
codex mcp |
Lists, adds and removes MCP servers |
codex doctor |
Builds a diagnostic report about your setup |
/model |
Changes the model or reasoning effort |
/review |
Reviews your working tree |
/compact |
Summarises the chat to free up context |
/usage |
Shows account token usage |
/quit |
Closes the CLI |
Type @ to search for a file and add its path to your prompt. In scripts, codex exec is read-only by default according to OpenAI’s non-interactive guide, so add --sandbox workspace-write when the task must edit files. It also expects a Git repository unless you pass --skip-git-repo-check.
AGENTS.md and MCP servers
Codex reads AGENTS.md files before it starts: a global one in ~/.codex, then the files from your project root down to the current folder, with closer files taking priority. To connect an outside tool through MCP, add a server from the terminal, as in OpenAI’s example codex mcp add context7 -- npx -y @upstash/context7-mcp, then check it with /mcp.
Using a custom provider or base URL
Codex CLI can send requests to another endpoint if that endpoint supports the OpenAI Responses API. Settings live in ~/.codex/config.toml (on Windows, %USERPROFILE%\.codex\config.toml). The block below follows the keys in OpenAI’s gateway guide; replace the model, address and variable name with your provider’s values.
model = "gpt-6.1-sol"
model_provider = "mygateway"
[model_providers.mygateway]
name = "My gateway"
base_url = "https://gateway.example.com/v1"
env_key = "CODEX_GATEWAY_API_KEY"
wire_api = "responses"
- Keep
modelandmodel_providerabove the first table header. - Put these lines in your user file. A project’s
.codex/config.tomlcannot set the model provider. - Set the environment variable in the shell that launches Codex; do not paste the key into the file or a repository.
wire_apiaccepts onlyresponses. An endpoint that offers Chat Completions alone will not work.- Run
/statusto confirm the model and provider in use.
A short reply does not prove that a gateway works: tool calls and streaming also have to pass. Only send code through a provider you trust.
Codex CLI usage limits
With ChatGPT sign-in, your plan sets an allowance that local messages and cloud chats share. OpenAI’s Codex pricing page gives these estimates of local messages per five-hour window, read on 29 November 2026.
| Model | Plus and Standard Business |
|---|---|
| GPT-6.2 Astra | 6–50 |
| GPT-6.2 Sol | 17–180 |
| GPT-6.1 Sol | 15–160 |
| GPT-6.1 Terra | 35–285 |
| GPT-6 Luna | 350–3,000 |
These are estimates, not fixed message caps, and the page says weekly limits may also apply. Pro plans currently have no five-hour limit. Usage per message changes with the model, the size of the task and its complexity. See what is left with /status or the usage dashboard at chatgpt.com/codex/settings/usage. Plus and Pro users can buy extra credits, and API key sessions are billed at API prices instead.
To make an allowance last, choose a smaller model for routine edits, keep tasks narrow, run /compact in long sessions and start a new chat for unrelated work.
Troubleshooting common errors
Start with codex doctor, which reports on your install, configuration, sign-in and runtime.
- “codex” is not recognised on Windows: open a new terminal and check your PATH.
Get-Command codexshows competing installs. - Linux sandbox warning: check that bubblewrap is installed and user namespaces work.
- Sign-in fails on a remote server: use device code login, or forward local callback port 1455 over SSH.
- Corporate proxy certificates: point
CODEX_CA_CERTIFICATEto a PEM bundle. - Custom provider rejects the key: confirm the variable reaches the Codex process.
- Model not found: check the exact model name your provider offers.
- Replies stall: a proxy may be buffering the stream.
Getting Codex access with USDT
AITopUp, an independent reseller with no tie to OpenAI, sells two routes into Codex for USDT. OpenAI’s terms do not allow its own API keys to be shared, bought or sold; the key sold here is not an OpenAI key.
- Third-party key: It is not an OpenAI key (OpenAI does not issue this key), so it cannot sign in to OpenAI’s platform. It comes with its own base URL ending in
/v1and covers nine models from GPT-5.5 to GPT-6.1; GPT-6.2 was not included as of 28 November 2026. Packs run from 10M to 500M tokens over 1 to 30 days, counted from first use, and unused tokens expire. For Codex CLI, run the setup tool in the guide sent with the key, choose CLI mode and paste the key. Warranty lasts 1 to 30 days by pack, from the day the order is marked complete. - ChatGPT sign-in: the private plan under ChatGPT Plus invites your own email to a ChatGPT Business workspace for 1 month, with Codex working and a 30-day warranty. The shared plan on the same page does not include Codex. If you want Plus billed to your own account, subscribe with OpenAI instead.
Orders usually arrive within 30 minutes once payment is confirmed. Read the warranty policy before ordering. Keys for other models are listed under AI API keys, and other assistants for programmers under coding tools. If a short trial is what you need, the smallest Codex API Key pack lasts one day. Weighing terminal agents against AI IDEs or prompt-to-app builders? Read our Cursor vs Claude Code comparison or our Base44 vs Lovable breakdown.
Codex CLI FAQ
Install it, open a project folder, run codex and sign in. Describe the task in plain words, approve actions when asked and review the changes with /diff. For scripts, use codex exec with your instruction in quotes.
It needs a sign-in or an API key, network access is off by default inside the sandbox, plan usage is limited, cloud features need ChatGPT sign-in, and custom providers must support the Responses API. Its answers and edits still need review.
Common ones are codex exec, resume, fork, review, login, logout, mcp, doctor and update. Inside a session, slash commands include /status, /model, /permissions, /init, /review, /diff, /compact, /resume, /mcp, /usage and /quit.
Yes. The openai/codex repository, written in Rust, is licensed under Apache-2.0. The IDE extension and Codex cloud are not open source. The repository accepts issues but not external pull requests.
Yes. Pipe the key into codex login --with-api-key. OpenAI then bills the usage to your Platform account at standard API rates, included plan credits are not used, and some cloud features are limited or unavailable.
Get these plans on AITopUp
Pay with USDT. Most orders are activated within 30 minutes, 24/7, and each product page shows its delivery time and warranty.