OpusGate

Codex CLI

OpenAI's Codex CLI supports custom model providers via ~/.codex/config.toml. Point it at OpusGate's OpenAI-compatible endpoint and run it on any model from the catalog. Unlike most tools, Codex reads the API key from an environment variable, not from the config file.

Required values
base_url: https://api.opusgate.dev/v1 (with /v1).
wire_api: chat — routes through OpenAI-style /chat/completions.
Key: env var OPUSGATE_API_KEY = your sk-og-... from the Keys page.

1. Install Codex

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

2. Config

Merge into ~/.codex/config.toml (create it if missing):

TOML
model = "claude-opus-4.8"
model_provider = "opusgate"

[model_providers.opusgate]
name = "OpusGate"
base_url = "https://api.opusgate.dev/v1"
env_key = "OPUSGATE_API_KEY"
wire_api = "chat"

3. Set the key and run

macOS / Linux
Bash
export OPUSGATE_API_KEY="sk-og-..."
codex

Add the export line to ~/.zshrc / ~/.bashrc to persist it.

Windows (PowerShell)
PowerShell
setx OPUSGATE_API_KEY "sk-og-..."
# setx affects NEW terminals — set it for this one too:
$env:OPUSGATE_API_KEY = "sk-og-..."
codex

Or auto-install: one script does everything

Installs Codex if it's missing (needs npm) and writes ~/.codex/config.toml (backing up an existing one to config.toml.bak). You still set the env var from step 3 yourself.

macOS / Linux
Bash
command -v codex >/dev/null 2>&1 || npm install -g @openai/codex
mkdir -p ~/.codex
[ -f ~/.codex/config.toml ] && cp ~/.codex/config.toml ~/.codex/config.toml.bak
cat > ~/.codex/config.toml <<EOF
model = "claude-opus-4.8"
model_provider = "opusgate"

[model_providers.opusgate]
name = "OpusGate"
base_url = "https://api.opusgate.dev/v1"
env_key = "OPUSGATE_API_KEY"
wire_api = "chat"
EOF
echo "Done — set OPUSGATE_API_KEY and run 'codex'."
Windows (PowerShell)
PowerShell
if (-not (Get-Command codex -ErrorAction SilentlyContinue)) { npm install -g @openai/codex }
$dir = "$env:USERPROFILE\.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 = "claude-opus-4.8"
model_provider = "opusgate"

[model_providers.opusgate]
name = "OpusGate"
base_url = "https://api.opusgate.dev/v1"
env_key = "OPUSGATE_API_KEY"
wire_api = "chat"
"@)
Write-Host "Done - set OPUSGATE_API_KEY and run 'codex'."

Troubleshooting

"Missing environment variable OPUSGATE_API_KEY"

The variable isn't visible to the shell running codex. On Windows remember that setx only affects new terminals; on macOS/Linux make sure the export is in the rc file of the shell you actually use.

Codex still asks for a ChatGPT login

It ignores the custom provider when model_provider isn't set at the top level of config.toml. Check for typos — the value must match the table name ([model_providers.opusgate]model_provider = "opusgate").

401 / 402 errors

401 → key mistyped or revoked (Keys); 402 → empty balance (top up). Full list: error codes.

← PreviousClaude CodeNext →Cursor