# Codex

> Add FreshRouter to Codex as a model provider, for the CLI, the desktop app and the IDE extension: one command, or one prompt for your agent.

There are two ways to set up Codex, and neither asks you to pick a model: run one command, or paste one prompt into a coding agent. Right after you create a key, the console shows both with your key already filled in, and its **Connect** page has them any time later.

## Run one command

Run it in a terminal, or in PowerShell on Windows, and paste your API key when it asks:

**macOS / Linux**

```bash
curl -fsSL https://freshrouter.com/install/codex.sh | bash
```

To skip the question, put the key after `bash -s --`. The console fills it in for you.

```bash
curl -fsSL https://freshrouter.com/install/codex.sh | bash -s -- sk-your-freshrouter-key
```

**Windows**

```powershell
irm https://freshrouter.com/install/codex.ps1 | iex
```

To skip the question, set the key in `$env:FRESHROUTER_API_KEY` first. The console fills it in for you.

```powershell
$env:FRESHROUTER_API_KEY="sk-your-freshrouter-key"; irm https://freshrouter.com/install/codex.ps1 | iex
```

The installer adds FreshRouter as a provider in `~/.codex/config.toml` and makes it the default, keeping the rest of the file and backing it up first. It saves your key in `~/.codex/freshrouter-api-key`, a file only you can read, which Codex reads each time it needs the key. The Codex CLI, the desktop app and the IDE extension share these settings, so one run sets up all three. Then restart Codex.

> On Windows the key goes into the `FRESHROUTER_API_KEY` user environment variable instead. A Codex older than 0.118 gets the same on macOS and Linux, in your shell profile, where a terminal sees it and the desktop app doesn't: update Codex and run the command again.

## Or have your coding agent do it

Paste this into a coding agent on the same computer. It asks you for your key, runs the command above and falls back to making the change by hand.

```text title="Prompt"
Set up Codex on this computer to use FreshRouter. First ask me for my FreshRouter API key (it starts with sk-), then put it below in place of <key>.

Run this in a terminal (macOS or Linux):

curl -fsSL https://freshrouter.com/install/codex.sh | bash -s -- <key>

On Windows, run this in PowerShell instead:

$env:FRESHROUTER_API_KEY="<key>"; irm https://freshrouter.com/install/codex.ps1 | iex

It adds FreshRouter as a model provider in ~/.codex/config.toml and makes it the default, saves my key in ~/.codex/freshrouter-api-key (on Windows, in my user environment variables) and backs up the config first. The Codex CLI, desktop app and IDE extension all read these settings. It's safe to run again.

If you can't run the command, make the same change by hand: in ~/.codex/config.toml, put the first two lines above the file's first [table] and add the two tables:

model = "gpt-6.1-sol"
model_provider = "freshrouter"

[model_providers.freshrouter]
name = "FreshRouter"
base_url = "https://freshrouter.com/v1"
wire_api = "responses"

[model_providers.freshrouter.auth]
command = "/bin/cat"
args = ["/full/path/to/.codex/freshrouter-api-key"]

Save my key, alone, in ~/.codex/freshrouter-api-key, readable only by me, and write that file's full path in args. On Windows (%USERPROFILE%\.codex\config.toml), leave the auth table out, add env_key = "FRESHROUTER_API_KEY" to the provider table and save my key in that variable with setx.

Don't ask me which model to use: the command keeps my current model if FreshRouter has it, and otherwise starts on gpt-6.1-sol. When it's done, tell me to restart Codex.
```

## Change the model

Nothing has to be chosen up front: the installer keeps your current model if FreshRouter has it, and otherwise starts you on `gpt-6.1-sol`. To pick another, add `--model` (`-Model` in PowerShell) to the command, or change `model` in `~/.codex/config.toml`:

**macOS / Linux**

```bash
curl -fsSL https://freshrouter.com/install/codex.sh | bash -s -- sk-your-freshrouter-key --model gpt-6.1-sol
```

**Windows**

```powershell
& ([scriptblock]::Create((irm https://freshrouter.com/install/codex.ps1))) -Key sk-your-freshrouter-key -Model gpt-6.1-sol
```

## Set it up by hand

Codex supports custom providers in `~/.codex/config.toml`. Put the first two lines above the file's first table, add the two tables, and write the full path of the key file in `args`:

```toml title="~/.codex/config.toml"
model = "gpt-6.1-sol"
model_provider = "freshrouter"

[model_providers.freshrouter]
name = "FreshRouter"
base_url = "https://freshrouter.com/v1"
wire_api = "responses"

[model_providers.freshrouter.auth]
command = "/bin/cat"
args = ["/Users/you/.codex/freshrouter-api-key"]
```

Then save your key in that file, and restart Codex:

```bash
printf '%s\n' "sk-your-freshrouter-key" > ~/.codex/freshrouter-api-key
chmod 600 ~/.codex/freshrouter-api-key
```

On Windows, the file is `%USERPROFILE%\.codex\config.toml`. Leave the `auth` table out and name an environment variable instead, then save the key with `setx FRESHROUTER_API_KEY sk-…` and restart Codex:

```toml title="config.toml"
[model_providers.freshrouter]
name = "FreshRouter"
base_url = "https://freshrouter.com/v1"
env_key = "FRESHROUTER_API_KEY"
wire_api = "responses"
```
