For the optional provider automation, use the current scripts https://www.bettertoken.ai/install-codex-provider.sh and https://www.bettertoken.ai/install-codex-provider.ps1; keep temporary values in TEMP only when the current instructions require it.
To continue setup, use your own BetterToken account and API Key. Create a BetterToken account
Codex CLI is OpenAI's coding agent for the terminal. You install one official codex client, then choose the authentication path that matches your account: sign in with ChatGPT, use an OpenAI API key, or configure a supported custom provider. You do not need a different Codex application for each API provider.
For a safe first run, install the CLI, confirm codex --version, complete exactly one authentication or provider setup path, and run a read-only task in a disposable repository before opening production code.
This guide was checked against the current OpenAI Codex repository and BetterToken Codex documentation on August 21, 2026. Installation commands and configuration fields can change, so use the linked primary documentation when applying them.
If you choose a custom pay-as-you-go provider, open the current BetterToken Codex setup guide, create your own API Key, and verify the first request before opening a production repository. BetterToken configures the official Codex CLI through a custom provider; it is not a separate Codex client or an OpenAI subscription.
Choose an installation method
| Method | Best for | Requirement |
|---|---|---|
| Standalone installer | A direct macOS, Linux, or Windows installation |
curl or PowerShell; Node.js is not required |
| Homebrew cask | macOS systems already managed with Homebrew | Homebrew |
| npm | Environments already managed with Node.js | A working Node.js and npm installation |
| GitHub Release binary | Controlled or offline-style installation workflows | Manual archive and PATH management |
The maintained Codex CLI is implemented in Rust. Node.js is required only for the npm installation method or for a separate provider setup script that explicitly depends on Node.js.
Check the prerequisites
OpenAI's installation documentation lists macOS 12+, Ubuntu 20.04+/Debian 10+, or Windows 11 through WSL2 as supported baselines, with Git recommended for repository workflows. Current native Windows support and sandbox details are documented separately and can evolve.
Before installation:
- Decide whether you will use official OpenAI authentication or a custom provider.
- Confirm that the target terminal can update its
PATH. - Start with a test repository rather than a production working tree.
- Keep API keys out of command arguments, source files, screenshots, and shell history.
Install Codex CLI
macOS and Linux: standalone installer
The current standalone installer does not require Node.js:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Open a new terminal if the installer changed your PATH, then verify the binary:
codex --version
macOS: Homebrew
brew install --cask codex
codex --version
npm: macOS, Linux, or Windows
npm install -g @openai/codex
codex --version
If the installation succeeds but codex is not found, inspect the global npm prefix:
npm config get prefix
Compare that location with your shell's PATH, correct the environment through the normal Node.js or shell configuration for your system, and open a new terminal. Do not append an assumed /bin path without checking the actual installation layout.
Windows: official PowerShell installer
Run the current official installer from PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
Then start a new PowerShell session and run:
codex --version
For Linux-oriented development on Windows, install the Linux CLI inside WSL2 and keep Linux projects in the WSL filesystem rather than under /mnt/ when practical. Check OpenAI's current Windows documentation before changing native sandbox settings.
GitHub Releases
The OpenAI Codex releases page provides platform-specific archives. Select the archive that matches both the operating system and CPU architecture, extract the executable, and place it in a directory already managed in your PATH. Verify the downloaded release and the resulting codex --version before use.
Choose one authentication path
Do not mix official OpenAI login state and a custom provider configuration while troubleshooting. Prove one path first.
Sign in with ChatGPT
Run:
codex login
Complete the browser flow, then check the saved authentication state:
codex login status
If the CLI is running on a headless machine, follow OpenAI's current device-code or API-key instructions rather than copying browser tokens between machines.
Use an OpenAI API key
Store the key in a secret manager or environment variable. Do not pass it as a visible command argument. Follow the current OpenAI Codex authentication guide for the supported login flow and credential storage behavior.
Use codex logout to remove saved official credentials. Treat local authentication files as secrets; do not print, commit, or manually share them.
Configure a custom provider
A custom provider still uses the same official Codex CLI. The provider configuration selects the Base URL, API protocol, model, and environment variable that supplies the key.
BetterToken supports a documented Codex custom-provider path through the OpenAI Responses API. The current Base URL is https://www.bettertoken.ai/v1, while model IDs and key-group names remain dynamic and must be copied from the current BetterToken interface or documentation.
Before configuring it, remove old OpenAI environment variables from the current shell if they would override the provider you intend to test:
unset OPENAI_API_KEY
unset OPENAI_BASE_URL
Then follow the current BetterToken Codex setup guide. It provides the current config.toml fields, wire_api = "responses", key environment variable, model selection, and startup command. Restart Codex completely after changing the configuration.
BetterToken is a pay-as-you-go model API service, not a replacement for the Codex CLI or a ChatGPT subscription. Use your own BetterToken account and API key, and verify current model availability and pricing on the day you configure it.
Complete a safe first run
Start in a disposable or non-critical repository. For example:
git clone https://github.com/openai/codex codex-test
cd codex-test
Run a read-only task:
codex --sandbox read-only "Explain the entry point of this project"
The first run is successful when all of these are true:
- Codex starts with the intended authentication or provider path.
- The response accurately identifies relevant project files.
- No files are modified.
- No write or execution permission is unexpectedly requested.
- The provider's usage record appears where applicable.
When using official OpenAI authentication, codex login status should show the expected state. When using BetterToken, a normal model response plus the corresponding request, model, status, and token usage in the BetterToken Dashboard confirms the API path more reliably than the OpenAI login-status command.
Troubleshoot by layer
codex: command not found
Open a new terminal, confirm the installation method completed successfully, and inspect the actual install location. For npm, use npm config get prefix; for a manual release, confirm the extracted executable is in a directory listed by PATH.
The browser does not open
Confirm that the machine has a usable browser and that callback traffic is not blocked. On a headless machine, use the currently documented device-code or API-key login path. Do not copy authentication files from another machine as a shortcut.
The custom provider returns 401 or 403
Check the key environment variable, whether the key belongs to the intended account and provider, and whether an old environment variable is overriding the configuration. Do not print the key while diagnosing it.
The custom provider returns 404 or an HTML page
Check that the Base URL belongs to the intended protocol and does not accidentally duplicate or omit the required version path. For BetterToken Codex, compare the value with the current Docs rather than reusing a Claude Code Base URL.
model not found
Copy a currently available model ID from the provider's current model list. Do not rely on a model name embedded in an old article, screenshot, or configuration example.
Configuration changes do not take effect
Stop all running Codex processes, open a new terminal, confirm which profile or config file is active, and retest with one small read-only request. Avoid changing authentication, model, Base URL, and sandbox policy simultaneously; otherwise the failing layer is hard to identify.
Final checklist
-
codex --versionreturns a version. - You selected exactly one authentication or provider path for the test.
- Secrets are stored outside source files and command history.
- The active Base URL, protocol, model, and key variable match the current provider documentation.
- A read-only task succeeds in a disposable repository without modifying files.
- Usage appears in the expected provider dashboard or account history.
Once these checks pass, open a real repository with the least permission needed for the next task. Review proposed commands and diffs before increasing autonomy.
Sources
- OpenAI Codex repository and installation options
- OpenAI Codex installation requirements
- OpenAI Codex authentication
- BetterToken Codex setup guide
Originally published on the BetterToken blog.
BetterToken provides pay-as-you-go access to AI model APIs through
OpenAI-compatible and Anthropic-compatible endpoints — useful if you are wiring
Claude Code, Codex, or your own tooling to a custom base URL.
See the docs to get started.
Top comments (0)