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

The snippets below use gpt-6.2-sol. Pick another model to update them.

Windows

  1. Install Codex CLI, then open a new terminal window.
    PowerShell
    powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
  2. 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"
  3. Create the file %USERPROFILE%\.codex\config.toml with this content. If the file already exists, put the first two lines at the very top and the rest at the end.
    config.toml
    model = "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
  4. Go to your project folder, start Codex and send a message.
    PowerShell
    codex

macOS

  1. Install Codex CLI, then open a new terminal window.
    Terminal
    curl -fsSL https://chatgpt.com/codex/install.sh | sh
  2. 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
  3. Create the file ~/.codex/config.toml with this content. If the file already exists, put the first two lines at the very top and the rest at the end.
    config.toml
    model = "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
  4. Go to your project folder, start Codex and send a message.
    Terminal
    codex

Linux

  1. Install Codex CLI, then open a new terminal window.
    Terminal
    curl -fsSL https://chatgpt.com/codex/install.sh | sh
  2. 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
  3. Create the file ~/.codex/config.toml with this content. If the file already exists, put the first two lines at the very top and the rest at the end.
    config.toml
    model = "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
  4. 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

If something goes wrong

What you seeWhat to do
401 or invalid_api_keyThe key is wrong, disabled or has extra spaces. Create a new key and paste it again.
402 or insufficient_quotaYour balance is empty. Top up under Billing.
404 or model_not_foundThe model ID has a typo. Copy it from the models page.
404 on every requestThe base URL is wrong. Check whether this tool needs the /v1 ending (see the steps above).
429Too many requests per minute. Wait a few seconds and retry.

Prefer a guided version? Open the setup wizard →