Skip to navigation
DocsCodex CLI setup: add a custom model provider in config.toml

Coding tools

Codex CLI setup: add a custom model provider in config.toml

In short: Codex CLI lets you add our gateway as a custom model provider through a model_providers entry in ~/.codex/config.toml, an API key env var and the Responses API.

Updated OpenAI formatCLIView .md
On this page
Base URLhttps://api.oneaiapikey.com/v1

Codex CLI lets you register any service that implements the OpenAI Responses API as a model provider. Our gateway does, so the whole setup is one small block in Codex’s config file plus an environment variable for your key. Every token Codex uses is billed against your prepaid balance at the published rates.

What do I need to use Codex CLI with the gateway?

Using Codex CLI with the gateway needs three things:

  • Codex CLI installed (for example with npm install -g @openai/codex) and starting normally.
  • A funded account: any balance above $0, the sign-up credit included, pays for every model; when it runs out, add $1 or more (create an account).
  • An API key from the console (it starts with sk-).

How do I store my key for Codex CLI?

Store your key in an environment variable, because Codex never reads the key from the config file. Instead, the provider entry names an environment variable (env_key) and Codex reads the key from there at startup. We’ll call it ONEAIAPIKEY_API_KEY, but any name works as long as the config matches.

macOS / Linux / Git Bash
# add to ~/.bashrc or ~/.zshrc to keep it
export ONEAIAPIKEY_API_KEY="sk-your-key-here"
Windows PowerShell
# current window only
$env:ONEAIAPIKEY_API_KEY = "sk-your-key-here"
# persist for new terminals (then open a new window)
setx ONEAIAPIKEY_API_KEY "sk-your-key-here"

setx only affects terminals opened afterwards, so close and reopen your terminal before running Codex.

How do I add the provider to config.toml?

Add the provider to config.toml as a model_providers entry. Codex keeps its settings in ~/.codex/config.toml (on Windows, %USERPROFILE%\.codex\config.toml). Create the file if it doesn’t exist, then add:

~/.codex/config.toml
# Default model and provider for every Codex session
model = "gpt-6.1-sol"
model_provider = "one-ai-api-key"

[model_providers.one-ai-api-key]
name = "One AI API Key"
base_url = "https://api.oneaiapikey.com/v1"
env_key = "ONEAIAPIKEY_API_KEY"
wire_api = "responses"
# Optional resilience settings
stream_idle_timeout_ms = 300000
request_max_retries = 4

What each line does:

  • model_provider tells Codex to send requests to the provider block below instead of OpenAI.
  • base_url must end in /v1. Codex appends the endpoint path (/responses) to it.
  • env_key is the name of the variable holding your key, not the key itself.
  • wire_api = "responses" selects the Responses API, which is what current Codex releases speak. Older guides on the web show wire_api = "chat"; that value has been retired in recent versions.
  • stream_idle_timeout_ms gives long reasoning steps more room before Codex treats a quiet stream as dead.

If you already have a config.toml, keep your other settings and just add these keys. TOML is strict: top-level keys such as model must appear before the first [section] header.

Which model should I use with Codex CLI?

Use a GPT model with Codex CLI: Codex is tuned for GPT models and their tool-calling style, so those are what we recommend here. Rates are USD per 1M tokens:

Model idGood forInputOutput
gpt-6.1-solCodex CLI, Tool calling, Long context$0.70$3.50
gpt-6-astraDeep research, Software engineering, Long agentic tasks$3.50$17.50
gpt-6-lunaHigh-volume chat, Classification, Light agents$0.035$0.175

gpt-6.1-sol is a strong default for agentic coding. Switch per session with the -m flag or a one-off config override:

Per-session model
codex -m gpt-6-luna
codex --config model='"gpt-6-astra"'

You can also change models inside the interactive UI with /model. Want Claude in the terminal instead? Use Claude Code, which talks to our Anthropic-compatible endpoint natively.

How do I verify Codex CLI works?

Verify the setup by running a one-shot, non-interactive prompt:

Smoke test
codex exec "Reply with the single word: ready"

You should see the model’s reply printed in the terminal, and a matching entry in your console’s usage log a few seconds later. In an interactive session, /status shows the active model and provider so you can confirm Codex picked up the right block.

How do I fix common Codex CLI errors?

The common Codex CLI errors and their fixes are listed below.

“Missing environment variable” or 401 Unauthorized. Codex couldn’t find a valid key. Check that the variable name in env_key matches exactly (it’s case-sensitive on macOS and Linux), that you opened a new terminal after setx, and that the key wasn’t revoked in the console. Paste the key without quotes or trailing spaces.

404 Not Found. The base URL is off by a path segment. It must be https://api.oneaiapikey.com/v1: without /v1 Codex calls a path that doesn’t exist, and with a full endpoint such as /v1/responses the path gets doubled.

Model not found / no available channel. The model value doesn’t match a catalogue id. Ids are lowercase and use dots and dashes exactly as shown on the models page.

Stream disconnected or the request times out. Codex always streams, so long outputs stay alive as long as tokens keep flowing. If a long reasoning pause trips the idle timer, raise stream_idle_timeout_ms. In your own scripts, use "stream": true for long generations: proxies cut idle non-streaming requests at roughly 100 seconds.

Codex ignores my provider. Usually a TOML ordering problem (top-level keys placed under a section) or a typo in model_provider. The value must equal the name after model_providers. exactly.

Balance ran out mid-task. Requests are refused at zero balance. Top up in the console and re-run; nothing in your config needs to change.

Next steps

Head to the quickstart for raw API and SDK examples using the same key, or browse the other tool guides. Compare per-model costs on the pricing page before kicking off a long autonomous run.

↑ ↓ moveEnter openEsc close
New accounts$10 credit on sign-up
Claim $10 credit →