Skip to content

Codex Setup Guide

This guide shows how to install OpenAI Codex on Windows and macOS, then connect it to PrimeRouter. After setup, Codex requests go through PrimeRouter and use your PrimeRouter token, balance, logs, and billing rules.

Scope

This page is for the guided setup flow on Windows and macOS. For manual config.toml editing, see OpenAI Codex CLI.

Prerequisites

ItemDescription
Windows or macOSWindows 10 / 11 or a recent macOS release is recommended
PrimeRouter accountSign up at primerouter.ai
PrimeRouter tokenCreate one at Console Tokens, usually starting with sk-
Codex installerDownload it from the official OpenAI Codex page

Download Setup Scripts

SystemDownloadCommand
WindowsDownload PowerShell scriptpowershell -ExecutionPolicy Bypass -File .\codex.ps1
macOS / LinuxDownload Shell scriptbash codex.sh

Safety note

The scripts write ~/.codex/config.toml and ~/.codex/auth.json. Existing config files are backed up first. You can download and inspect the scripts before running them.

Coming from another provider? The scripts reuse the model_provider id this machine already had, so your codex resume history stays visible. Set PRIMEROUTER_CODEX_PROVIDER_ID=primerouter before running if you prefer a clean id.

Windows Flow

1. Download and install Codex

Open the OpenAI Codex page in your browser.

Open the OpenAI Codex page

Open the downloaded installer. Codex checks the runtime environment and installs itself automatically.

Codex checks and installs automatically

After installation, Codex may start automatically. Quit Codex first so the new PrimeRouter config can be loaded cleanly later.

Quit Codex

2. Run the Windows setup script

Download the Windows PowerShell setup script.

Download the PrimeRouter Codex setup script

After downloading, right-click the script and choose Run with PowerShell.

Run the script with PowerShell

PowerShell opens the interactive setup flow.

PowerShell setup window

You can also run the script from PowerShell manually:

powershell
powershell -ExecutionPolicy Bypass -File .\codex.ps1

3. Create a PrimeRouter token

When the script asks for a PrimeRouter token, open Console Tokens.

Open the PrimeRouter tokens page

Create a dedicated token for Codex. This makes it easier to inspect logs, restrict models, or disable Codex access separately later.

Create a PrimeRouter token

Copy the new token. The full token is shown only once, so store it safely.

Copy the PrimeRouter token

4. Enter the token and write config

Return to the PowerShell window, paste the PrimeRouter token, and press Enter.

Enter the PrimeRouter token

The script writes the Codex config automatically. After it completes, fully quit Codex and open it again.

Restart Codex

5. Choose a model in Codex

After reopening Codex, follow the UI prompts to enter the model setup or login flow.

Open the Codex setup entry

If Codex asks for a key again, enter the PrimeRouter token you just created.

Enter the PrimeRouter token in Codex

Choose a model. The example uses gpt-5.5, but you can choose any available model in your PrimeRouter console.

Choose gpt-5.5

6. Verify the setup

Send a simple question or coding task in Codex. If Codex responds normally, Windows is now connected through PrimeRouter.

Codex setup success

macOS Flow

1. Download and install Codex

Open the OpenAI Codex get started page and download Codex.

Open the OpenAI Codex macOS download page

Open the downloaded installer and complete the installation.

Open the Codex macOS installer

Install Codex on macOS

2. Download and run the macOS setup script

Download the macOS / Linux setup script, then open the download folder.

Open the downloads folder

Confirm that codex.sh is in the folder.

Confirm the setup script file

Open the macOS Terminal app.

Open Terminal

Drag codex.sh into Terminal. Terminal will paste the script path, for example:

bash
/Users/your-name/Downloads/codex.sh

Drag the setup script into Terminal

Terminal shows the script path

Grant execute permission:

bash
chmod +x /Users/your-name/Downloads/codex.sh

Then run the script:

bash
/Users/your-name/Downloads/codex.sh

The script opens a system prompt for your PrimeRouter token. If a dialog is unavailable, it falls back to hidden terminal input.

Run the macOS setup script

3. Create and enter a PrimeRouter token

Open Console Tokens and create a dedicated token for Codex.

Create a PrimeRouter token

Copy the new token. The full token is shown only once, so store it safely.

Copy the PrimeRouter token

Paste the token into the prompt and continue.

Enter the PrimeRouter token

When you see the success message, the PrimeRouter config has been written to Codex.

macOS setup success message

4. Restart Codex and choose a model

Restart Codex and follow the UI prompts.

Restart Codex

If Codex asks for a key again, enter the PrimeRouter token you just created.

Enter the PrimeRouter token in Codex

Choose a model. The example uses gpt-5.5, but you can choose any available model in your PrimeRouter console.

Choose a Codex model

5. Verify the setup

Send a simple question or coding task in Codex. If Codex responds normally, macOS is now connected through PrimeRouter.

macOS Codex setup success

Optional: Choose a Default Model

The default model is gpt-5.6-sol. You can override it when running the script:

powershell
$env:PRIMEROUTER_MODEL = "gpt-5.4-mini"; irm https://primerouter.ai/install/codex.ps1 | iex
bash
PRIMEROUTER_MODEL=gpt-5.4-mini bash codex.sh

Troubleshooting

SymptomCauseFix
Invalid keyToken was copied incorrectly, disabled, or incompleteCreate a new PrimeRouter token and copy the full value
Model not foundModel id is wrong or unavailable to the token groupCheck available models in the PrimeRouter console
Script cannot runWindows PowerShell execution policy blocks itUse Run with PowerShell or ExecutionPolicy Bypass
Codex still asks for setupCodex was not restarted or config was not reloadedFully quit and reopen Codex

Built for transparent, auditable, crypto-native AI inference. About · Terms · Privacy