Skip to main content
Codex CLI and Codex App connect to BetterToken through OpenAI Responses. The configuration file is ~/.codex/config.toml, and the API Key is supplied through BETTERTOKEN_API_KEY.

Key settings

Prerequisites

Install

Command-line setup

The BetterToken Automatic setup script writes the Codex provider configuration. It requires Node.js and prompts for the API Key or Model ID when they are not passed as arguments.
After it finishes, open ~/.codex/config.toml (or %USERPROFILE%\.codex\config.toml on Windows), confirm that model, review_model, and the BetterToken provider were written correctly, and fully restart Codex.

Manual setup

GPT, Kimi, and GLM use the same config.toml structure. Only replace YOUR_MODEL_ID with a current Model ID from the selected provider. One-click command-line setup is currently available for GPT only.

Set the API Key

Add this line to ~/.zshrc or ~/.bashrc to persist it.
Do not put a BetterToken API Key in ~/.codex/auth.json. That file is for the official Codex login; a custom provider should read the environment variable through env_key.

Configure config.toml

Edit ~/.codex/config.toml:
model_provider = "custom" must match the [model_providers.custom] table. Replace both YOUR_MODEL_ID values with a current complete Model ID.

Verify the connection

Open a new terminal and run:
Send a short task. A streamed response without login, 401, or model errors confirms the setup.

Switch models

Change model and, optionally, review_model. Save the file, stop the current Codex process, and start it again. Use the Model ID from the Setup dialog or model plaza.

Common errors

Advanced setup

Supported providers

Statuses apply to the BetterToken setup documented on this page.
  • Command-line + manual setup: use a generated command or follow the complete manual steps.
  • Manual setup: enter the API Key, Base URL, and Model.
  • Not supported: no verified direct setup is currently available.

Codex Extension

The Codex VS Code Extension shares config.toml, but preserving the official login uses a different authentication configuration. See the Codex Extension setup guide.
CLI/App setup and Extension setup with an official login are alternatives. Do not paste two [model_providers.custom] tables into the same TOML file.

Official reference

Technical details

Codex uses OpenAI Responses. Set base_url to https://bettertoken.ai/v1 and keep wire_api = "responses". Codex appends /responses.