tutorial

Connect Codex CLI to Token Station on Windows, macOS, and Linux

Codex CLI supports custom model providers in config.toml. After adding Token Station, you can keep using codex and codex exec while sending requests through your Token Station API key.

This guide is for the command-line version of Codex. The Codex App can inherit environment variables differently, especially on macOS and Linux desktops, so do not mix the two setup procedures.

Before you start

Three things need to be in place before you edit any configuration:

  • Codex CLI is installed and codex --version returns version information
  • You have a working Token Station API key
  • Your account has access to the target model, and credit to spend on it

Never expose a real API key in documentation, screenshots, chats, or repositories.

Configure the Token Station provider

Codex CLI reads its user configuration from:

  • Windows: %USERPROFILE%\.codex\config.toml
  • macOS and Linux: ~/.codex/config.toml

Add this block:

model = "openai/gpt-5.6-sol"
model_provider = "token_station"

[model_providers.token_station]
name = "Token Station"
base_url = "https://bec.bytefuture.ai/v1"
env_key = "TOKEN_STATION_API_KEY"
wire_api = "responses"

Merge these fields with any existing configuration instead of overwriting settings you still need.

Field Purpose
model Complete default model ID
model_provider Provider block Codex should use
name Provider display name
base_url Token Station API root
env_key Environment variable that stores the API key
wire_api Selects the Responses API

Four details here are easy to get wrong:

  • model_provider = "token_station" matches [model_providers.token_station]
  • base_url ends at /v1, without /responses
  • wire_api is "responses"
  • The model ID keeps its provider prefix

The examples use openai/gpt-5.6-sol. Use the complete current ID shown by Token Station.

The provider block names the environment variable but does not supply its value. That part depends on your operating system.

Windows: load the API key

Load the key temporarily

Run this in PowerShell:

$env:TOKEN_STATION_API_KEY = "YOUR_REAL_API_KEY"

The variable applies only to the current PowerShell process and its child processes, which is useful for an initial test.

Save a user environment variable

[Environment]::SetEnvironmentVariable(
  "TOKEN_STATION_API_KEY",
  "YOUR_REAL_API_KEY",
  "User"
)

Close the terminal and open a new PowerShell window, since a process that is already running will not pick up a variable saved after it started.

Check that the variable exists without printing the key:

if ([string]::IsNullOrEmpty($env:TOKEN_STATION_API_KEY)) {
  "TOKEN_STATION_API_KEY is not set"
} else {
  "TOKEN_STATION_API_KEY is set"
}

To remove it later:

[Environment]::SetEnvironmentVariable(
  "TOKEN_STATION_API_KEY",
  $null,
  "User"
)

macOS and Linux: load the API key

Set the variable in the terminal that will run Codex CLI:

export TOKEN_STATION_API_KEY='YOUR_REAL_API_KEY'

Check that it exists:

if [ -n "${TOKEN_STATION_API_KEY:-}" ]; then
  echo "TOKEN_STATION_API_KEY is set"
else
  echo "TOKEN_STATION_API_KEY is not set"
fi

To load it in new terminals, add the export command to the configuration file for your shell:

Shell Common configuration file
Zsh ~/.zshrc
Bash ~/.bashrc
Fish ~/.config/fish/config.fish, with different syntax

Open a new terminal after editing, or run source ~/.zshrc or source ~/.bashrc.

A key in a shell configuration file is stored as plaintext. Keep that file out of Git and public sync folders.

Verify the connection

A config.toml that parses is not proof that requests reach Token Station. Start an interactive session:

codex

Then send this prompt:

Reply only: Token Station test succeeded

You can also run a non-interactive request:

codex exec 'Reply only: Token Station test succeeded'

In PowerShell, use double quotes:

codex exec "Reply only: Token Station test succeeded"

After the response arrives, open the Token Station dashboard. Check the request time, status, and model under Recent Activity.

The setup is complete only when:

  • codex or codex exec returns a normal result
  • Token Station shows the matching request
  • The recorded model matches the configuration

Troubleshooting

codex command not found

Confirm that Codex CLI is installed and its installation directory is in PATH. Open a new terminal after installation or a PATH change, then run codex --version.

Codex cannot find the API key

Four things have to line up:

  • The variable is named TOKEN_STATION_API_KEY
  • config.toml uses env_key = "TOKEN_STATION_API_KEY"
  • Codex starts from the same terminal that contains the variable
  • A new terminal was opened after saving a persistent variable

401 or 403 response

The key may be invalid, contain extra whitespace, lack model access, or have no available credit.

404 response

Recheck these two fields:

base_url = "https://bec.bytefuture.ai/v1"
wire_api = "responses"

Do not append /responses to the base URL.

Model not found or request failed

Use the complete model ID currently supplied by Token Station and keep its provider prefix.

Old configuration is still active

Confirm that you edited the current user’s config.toml, that the file extension is correct, and that you restarted the Codex CLI process.

Security notes

  • Do not put a real key in config.toml
  • Do not commit shell configuration files that contain keys
  • Prefer temporary environment variables on shared computers
  • Revoke and replace a key immediately if it may have leaked

References