Setup guide
Connect Codex CLI
Codex CLI is OpenAI's coding agent for the terminal. You add CheapTokens as a model provider in its config.toml.
Before you start
- A CheapTokens account with some balance. Create one if you haven't.
- Your API key from Dashboard → API key. It starts with
ct_live_. - A model that supports the OpenAI Responses format. GPT models all do, and the model list on this page shows the others.
The snippets below use gpt-6.2-sol. Pick another model to update them.
Windows
-
Install Codex CLI, then open a new terminal window.PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
-
Save your key as an environment variable. Close PowerShell and open it again so the new variables load.PowerShell
setx CHEAPTOKENS_API_KEY "YOUR_API_KEY"
-
Create the file
%USERPROFILE%\.codex\config.tomlwith this content. If the file already exists, put the first two lines at the very top and the rest at the end.config.tomlmodel = "gpt-6.2-sol" model_provider = "cheaptokens" [model_providers.cheaptokens] name = "CheapTokens" base_url = "https://cheaptokens.pw/v1" env_key = "CHEAPTOKENS_API_KEY" wire_api = "responses" requires_openai_auth = false
-
Go to your project folder, start Codex and send a message.PowerShell
codex
macOS
-
Install Codex CLI, then open a new terminal window.Terminal
curl -fsSL https://chatgpt.com/codex/install.sh | sh
-
Save your key as an environment variable. The last line reloads your shell settings, so the variables work straight away.Terminal
echo 'export CHEAPTOKENS_API_KEY="YOUR_API_KEY"' >> ~/.zshrc source ~/.zshrc
-
Create the file
~/.codex/config.tomlwith this content. If the file already exists, put the first two lines at the very top and the rest at the end.config.tomlmodel = "gpt-6.2-sol" model_provider = "cheaptokens" [model_providers.cheaptokens] name = "CheapTokens" base_url = "https://cheaptokens.pw/v1" env_key = "CHEAPTOKENS_API_KEY" wire_api = "responses" requires_openai_auth = false
-
Go to your project folder, start Codex and send a message.Terminal
codex
Linux
-
Install Codex CLI, then open a new terminal window.Terminal
curl -fsSL https://chatgpt.com/codex/install.sh | sh
-
Save your key as an environment variable. The last line reloads your shell settings, so the variables work straight away.Terminal
echo 'export CHEAPTOKENS_API_KEY="YOUR_API_KEY"' >> ~/.bashrc source ~/.bashrc
-
Create the file
~/.codex/config.tomlwith this content. If the file already exists, put the first two lines at the very top and the rest at the end.config.tomlmodel = "gpt-6.2-sol" model_provider = "cheaptokens" [model_providers.cheaptokens] name = "CheapTokens" base_url = "https://cheaptokens.pw/v1" env_key = "CHEAPTOKENS_API_KEY" wire_api = "responses" requires_openai_auth = false
-
Go to your project folder, start Codex and send a message.Terminal
codex
Check that it works
Send a short message in Codex CLI, then open Dashboard → Usage. The request appears there within a few seconds, with its model, tokens and cost.
Good to know
- Codex only speaks the OpenAI Responses format, so it works with the models in the list on this page, not with every model.
- Codex may warn that it has no metadata for a custom model. The model still works.
- The Codex extension for VS Code (
code --install-extension openai.chatgpt) reads the sameconfig.toml. Start VS Code from a terminal that has the key variable, or restart your computer after setting it. - Switch model with
codex --model gpt-6.2-solor/modelinside Codex. - Provider settings only work in the config file in your home folder, not in a project's
.codexfolder.
If something goes wrong
| What you see | What to do |
|---|---|
401 or invalid_api_key | The key is wrong, disabled or has extra spaces. Create a new key and paste it again. |
402 or insufficient_quota | Your balance is empty. Top up under Billing. |
404 or model_not_found | The model ID has a typo. Copy it from the models page. |
| 404 on every request | The base URL is wrong. Check whether this tool needs the /v1 ending (see the steps above). |
| 429 | Too many requests per minute. Wait a few seconds and retry. |
Prefer a guided version? Open the setup wizard →