config.toml and auth.json for local tasks. This setup uses a BetterToken API Key through OpenAI Responses.
Key settings
Prerequisites
- Install Node.js
- Create a BetterToken API Key
- Copy a Model ID from the model plaza or the key Setup dialog
Install
Locate and back up your files
If you use a customCODEX_HOME, edit config.toml and auth.json in that directory. Otherwise use ~/.codex on macOS / Linux or %USERPROFILE%\.codex on Windows. CLI and App must use the same directory. WSL has its own user directory.
Fully quit Codex before editing. Back up both files to a private location. Create missing files if needed. Replace existing settings instead of appending duplicate keys or tables; keep unrelated settings.
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.- macOS / Linux
- Windows
Manual setup
Edit config.toml
This guide uses user-levelconfig.toml. Put root keys before all TOML tables, not inside [projects."<path>"]; that table stores project trust_level. The selected provider ID must match its table name. For file authentication, remove env_key and experimental_bearer_token from the selected provider.
gpt-6-astra). For another model, copy its complete ID from the model plaza and replace model. GPT, Kimi, and GLM use the same file-auth structure; automatic setup is available for GPT.
Edit auth.json
auth.json is in the same directory as config.toml. If auth.json does not exist, create it in that directory. Set its contents to the following JSON, replace YOUR_API_KEY with your BetterToken API Key, and save the file.
Configuration parameters
File authentication here switches to API Key mode. To keep your official account, use official-login preservation; do not mix the two modes. They differ by authentication goal, not by CLI, App, or Extension.
Optional tuning
These three settings are optional tuning, not connection requirements. Merge them into the existing[model_providers.bettertoken] table when needed; do not create a duplicate table.
Configuration layers and legacy keys
Do not put model or reasoning settings inside[projects."<path>"]. Project-specific models can use root keys in a trusted project’s .codex/config.toml; provider and authentication settings remain in user config. Current named profiles use NAME.config.toml under CODEX_HOME, selected with codex --profile NAME, not legacy [profiles.NAME] tables or the root profile selector.
Verify the connection
Save both files. In the terminal, start a new Codex CLI session directly:Switch models
Changemodel 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
For401, 403, or a sign-in prompt, check the active directory, the Key in auth.json, auth_mode = apikey, cli_auth_credentials_store = file, and requires_openai_auth = true. For provider or model errors, check the matching provider ID, https://bettertoken.ai/v1, wire_api = responses, and the model’s availability. If changes do not apply, check configuration overrides and confirm CLI and App use the same CODEX_HOME.
Advanced setup
Codex Extension
CLI, App, and Extension share configuration when they use the sameCODEX_HOME. Choose authentication by goal: API Key access or preserving official sign-in.
Codex Extension setup guide
Related FAQ
- What is Codex CLI?
- Codex CLI vs Codex App vs Codex Web
- Codex config.toml setup guide
- What are model_provider, base_url, and wire_api?
- What do review_model and reasoning_effort mean?
- What is AGENTS.md and how should you write it?
- What are Codex CLI sandbox and approval modes?
- How to keep the official Codex login with a third-party API
- OpenAI-compatible API vs Anthropic-compatible API
- Claude Code vs Codex CLI
- Manage the Codex provider with CC Switch
Official reference
Technical details
Responses protocol
Responses protocol
Codex uses OpenAI Responses. Set
base_url to https://bettertoken.ai/v1 and keep wire_api = "responses". Codex appends /responses.
