Codex CLI

Connect Codex CLI to Token Share

Install Codex CLI and point it at Token Share with a ready-made config.toml, on macOS, Linux or Windows. Plus a one-off command that changes nothing.

Install Codex CLI

  1. 1Sign in to Token Share and open the API Keys page.
  2. 2Click Create key, choose the Inference type, and copy the key that starts with sk-token-. It is shown in full only once.
  3. 3Top up with USDT on the Billing page. Claude models are paid from topped-up balance only.

Codex CLI installs with npm, which comes with Node.js 22 or newer.

  1. 1Download Node.js from nodejs.org: pick the LTS version and click macOS Installer (.pkg), then run it. Linux users can install it with their package manager.
  1. 2Open Terminal: press ⌘ + Space, type “Terminal” and press Enter, or find it in Launchpad under Other.
  1. 1Download Node.js from nodejs.org: pick the LTS version and click Windows Installer (.msi), then click through the installer with the defaults.
  1. 2Open a terminal: press Win + S, search for Terminal (on Windows 10, PowerShell) and open it. Every command below is typed there.

If PowerShell says a script such as npm.ps1 “cannot be loaded because running scripts is disabled on this system”, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, answer Y, and run the command again.

Then, in the terminal:

npm install -g @openai/codex
codex --version

If the download stalls, add --registry=https://registry.npmmirror.com to the end of the install command.

Connect to Token Share

This writes Token Share into ~/.codex/config.toml and saves your key as TOKEN_SHARE_KEY. An existing config is kept as config.toml.bak.

Change one thing only: replace <your-pool-api-key> with your key, keeping the quotes around it. Then paste the whole block into the terminal and press Enter.

mkdir -p ~/.codex
[ -f ~/.codex/config.toml ] && cp ~/.codex/config.toml ~/.codex/config.toml.bak
cat > ~/.codex/config.toml <<'EOF'
model_provider = "token_share"
model = "gpt-5.6-sol"

[model_providers.token_share]
name = "OpenAI"
base_url = "https://token-share.app/v1"
wire_api = "responses"
env_key = "TOKEN_SHARE_KEY"
requires_openai_auth = false
EOF
[ -f ~/.codex/auth.json ] || printf '%s\n' '{"OPENAI_API_KEY":"sk-placeholder"}' > ~/.codex/auth.json

SHELL_RC="$HOME/.zshrc"; case "$SHELL" in *bash*) SHELL_RC="$HOME/.bashrc";; esac
echo 'export TOKEN_SHARE_KEY="<your-pool-api-key>"' >> "$SHELL_RC"
source "$SHELL_RC"
$key = "<your-pool-api-key>"

$dir = "$HOME\.codex"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
if (Test-Path "$dir\config.toml") { Copy-Item "$dir\config.toml" "$dir\config.toml.bak" -Force }
[IO.File]::WriteAllText("$dir\config.toml", @'
model_provider = "token_share"
model = "gpt-5.6-sol"

[model_providers.token_share]
name = "OpenAI"
base_url = "https://token-share.app/v1"
wire_api = "responses"
env_key = "TOKEN_SHARE_KEY"
requires_openai_auth = false
'@)
if (-not (Test-Path "$dir\auth.json")) { [IO.File]::WriteAllText("$dir\auth.json", '{"OPENAI_API_KEY":"sk-placeholder"}') }

[Environment]::SetEnvironmentVariable("TOKEN_SHARE_KEY", $key, "User")
$env:TOKEN_SHARE_KEY = $key

Open a new terminal, go to your project folder and run codex.

To use another model, change model = "gpt-5.6-sol" in ~/.codex/config.toml to any GPT id from the model list.

Try it without changing any config

This is the same command as the dashboard’s quick start. It passes every setting on the command line, so nothing on disk changes except a placeholder auth.json on first run.

export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
mkdir -p "$CODEX_HOME"

# API key
export TOKEN_SHARE_KEY="<your-pool-api-key>"

# First-time initialization
[ -f "$CODEX_HOME/auth.json" ] || {
  printf '%s\n' '{"OPENAI_API_KEY":"sk-placeholder"}' > "$CODEX_HOME/auth.json"
  chmod 600 "$CODEX_HOME/auth.json"
}

# Run Codex
codex \
  --config 'model_provider=token_share' \
  --config 'model_providers.token_share.name="OpenAI"' \
  --config 'model_providers.token_share.base_url="https://token-share.app/v1"' \
  --config 'model_providers.token_share.wire_api="responses"' \
  --config 'model_providers.token_share.env_key="TOKEN_SHARE_KEY"' \
  --config 'model_providers.token_share.requires_openai_auth=false' \
  --config 'check_for_update_on_startup=false' \
  --config 'analytics.enabled=false' \
  --config 'feedback.enabled=false' \
  --model 'gpt-5.6-sol'

This command is for macOS and Linux terminals. On Windows, use the config file above instead.

Switching back to a ChatGPT account

Rename ~/.codex/config.toml.bak back to config.toml. If there was no backup, delete config.toml. Then restart Codex.

Troubleshooting

What you seeFix
Missing environment variable: TOKEN_SHARE_KEYCodex was started before the key was saved. Quit it completely and start it again; on Windows, also open a new terminal.
401 invalid api keyThe key was pasted wrong. Copy it again and rerun the setup block.
It still asks you to sign in to ChatGPTThe config was not picked up. Check that ~/.codex/config.toml starts with model_provider = "token_share", then restart Codex.

Prefer clicking to editing files? CC Switch can write the same setup for you.

Ready? Three steps to start

  1. 1Sign in to the console
  2. 2Top up your balance
  3. 3Create an API key