Use a Third-Party API with Codex CLI: Custom model_providers in config.toml

Disclosure: LLM API Guide is maintained by the SeedRouter team, and this guide uses SeedRouter as the example. The same steps work with any gateway that supports the OpenAI Responses API.

When this helps

  • You want Codex CLI to use a cheaper or more resilient model route instead of only your official account quota.
  • Your team buys API access centrally and wants one base URL and API key per project for usage and billing.
  • You want to switch between the official sign-in and a gateway without rewriting your setup each time.

Step 1: Collect three values

ValueWhat it isSeedRouter example
Base URLThe gateway's OpenAI-compatible endpointhttps://seedrouter.net/v1
API keyCreated in the gateway dashboardsk-... (create it only on seedrouter.net)
Model IDA model from the gateway cataloge.g. gpt-6.1-sol; copy the exact ID from the dashboard

Double-check the domain. Several sites use similar names, and a mistyped base URL sends your requests to a different service. SeedRouter's only official domain is seedrouter.net; see its official channels page.

Step 2: Edit ~/.codex/config.toml

Location:

  • macOS / Linux: ~/.codex/config.toml
  • Windows: C:\Users\<you>\.codex\config.toml

Create the file if it does not exist, then add:

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

[model_providers.seedrouter]
name = "SeedRouter"
base_url = "https://seedrouter.net/v1"
env_key = "SEEDROUTER_API_KEY"
wire_api = "responses"
requires_openai_auth = false
KeyPurpose
model_providerSelects the provider named seedrouter below
modelDefault model ID
base_urlGateway endpoint; Codex appends /responses
env_keyEnvironment variable Codex reads the API key from, so the key never sits in the file
wire_apiProtocol; responses means the OpenAI Responses API
requires_openai_authfalse because this provider does not use the ChatGPT sign-in

Step 3: Export the API key

macOS / Linux (zsh or bash):

echo 'export SEEDROUTER_API_KEY="sk-your-key"' >> ~/.zshrc
source ~/.zshrc

Use ~/.bashrc instead of ~/.zshrc if you run bash.

Windows PowerShell:

setx SEEDROUTER_API_KEY "sk-your-key"

setx only affects new terminals, so close and reopen PowerShell afterwards.

Step 4: Verify

Check the key and URL first. A model list in the response means authentication works:

curl https://seedrouter.net/v1/models \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY"

Then start Codex:

codex

Ask a quick question. If it answers, you are done, and the request also appears in the usage logs of the SeedRouter dashboard.

Switch between the official sign-in and the gateway

Keep both setups in one file with a profile:

[profiles.seedrouter]
model = "gpt-6.1-sol"
model_provider = "seedrouter"

Run codex --profile seedrouter to use the gateway; without the flag Codex uses the top-level defaults. If you prefer a GUI, CC Switch can manage several providers for Codex and Claude Code.

Common errors

SymptomLikely causeFix
401 / 403Extra whitespace in the key, variable not loaded, or a key from another siteCopy the key again, reopen the terminal, check echo $SEEDROUTER_API_KEY (PowerShell: $env:SEEDROUTER_API_KEY)
404base_url is missing /v1 or misspelledCompare it with the gateway docs
Model not foundThe model ID is not in your account's catalogCopy the exact ID from the dashboard model list
No change after editingCodex was already running, or the terminal was not reopenedQuit Codex and open a new terminal
Requests go somewhere elseOPENAI_BASE_URL, OPENAI_API_KEY or similar variables are setCheck with env | grep OPENAI (PowerShell: Get-ChildItem Env:OPENAI*) and remove conflicts

Summary

Three things connect Codex to a gateway: a provider table in config.toml, an environment variable for the key, and wire_api = "responses". If you do not have a gateway account yet, you can sign up on the SeedRouter website. New accounts get two free popular-model trials, and the homepage compares each model's price with official API pricing.

FAQ

Can I still sign in to Codex with my ChatGPT account?

Yes. The official sign-in and a custom provider are separate settings. Switch back to the default provider or use a profile, and neither overwrites the other.

Should base_url include /v1?

Follow the gateway's docs. For SeedRouter use https://seedrouter.net/v1; Codex appends /responses.

Should wire_api be chat or responses?

Use responses when the gateway supports the OpenAI Responses API, as SeedRouter does. Gateways that only offer Chat Completions need a translation layer such as CC Switch local routing.

I edited config.toml but nothing changed. Why?

Codex reads its config and environment at startup. Quit Codex, open a new terminal and start it again.