Codex CLI Custom Provider:
config.toml Setup for App and CLI

Run Codex on your own API key with a custom model provider in config.toml. Setup for the CLI and the ChatGPT desktop app, env vars and common errors.

Updated 7 min read

Codex lets you add a custom model provider in its config file and send requests to an OpenAI-compatible API. Install Codex, add Brioi as a provider in config.toml, and put your API key in an environment variable. The config is the same for the ChatGPT desktop app and the Codex CLI. What differs is how each one picks up the environment variable.

Written for Codex CLI 0.167 and checked against OpenAI’s Codex docs in November 2026. API usage is billed per token.

Why use a custom provider

Codex is OpenAI’s coding agent. It runs inside the ChatGPT desktop app (pick Codex from the ChatGPT dropdown) and as a terminal tool, the Codex CLI. By default it calls models through OpenAI, either with a ChatGPT plan or an OpenAI API key.

Two things send teams to a custom provider:

  • Region. OpenAI’s supported countries list doesn’t include Russia, Belarus, Iran, Hong Kong, Macau, mainland China, Syria, Cuba, Venezuela or North Korea, so OpenAI API access isn’t offered there.
  • Billing. A ChatGPT plan is paid per seat and metered by a 5-hour usage window. A custom provider is billed per token and has no plan limits.

Codex’s config supports custom model providers (model_providers in OpenAI’s docs). Each one sets the endpoint, the wire protocol and the environment variable holding the key, so Codex can send its model requests to a compatible API such as Brioi. Brioi works in regions OpenAI doesn’t serve, and its pricing is about 10–50% of the official price, from one balance shared with Claude, Gemini and video models.

Codex plans vs an API key

For comparison, OpenAI’s Codex options (Codex pricing, USD, checked 2026-11):

Option Price Codex usage
Free / Go $0 / $8 a month GPT-6 Luna in the desktop app, subject to rollout
Plus $20 a month Estimated local messages per 5 hours, for example 15–160 on GPT-6.1 Sol; weekly caps can apply
Pro From $100 a month ($100, $200 or $500) No 5-hour limit at present
Business $20 per user a month billed annually, $25 monthly Same 5-hour estimates as Plus
OpenAI API key Pay as you go Standard API rates, no plan allowance, no cloud features

A custom provider sits in the last row: CLI and desktop work billed per token. Cloud features such as Codex cloud tasks, GitHub code review and Slack still need a ChatGPT sign-in.

Before you start

  • API key: create one on the Brioi API keys page, in a group that includes the GPT models you plan to use. No account yet? Sign up on the main site first.
  • Desktop app: the ChatGPT desktop app installed and able to open Codex, plus a ChatGPT account you can sign in with.
  • CLI: a terminal. The official installer is a standalone script; the npm route needs Node.js.

Codex in the ChatGPT desktop app

Works on macOS and Windows. You stay signed in to ChatGPT in the app, and model requests go out with your Brioi key.

1. Sign in to ChatGPT

Open the ChatGPT desktop app, sign in and finish the browser step. Back in the app, check that the account menu shows you as signed in.

2. Set the environment variable

Codex reads the key from the BRIOI_API_KEY environment variable. A desktop app doesn’t inherit variables from your shell, so an export in a terminal won’t reach it. Use one of these options.

Windows, in PowerShell:

setx BRIOI_API_KEY "YOUR_API_KEY"

macOS, in Terminal:

launchctl setenv BRIOI_API_KEY "YOUR_API_KEY"

The macOS setting is lost when you restart the computer, so run it again after each reboot. For a setting that lasts, the Codex docs suggest putting the variables desktop apps need in ~/.codex/.env (%USERPROFILE%\.codex\.env on Windows):

export BRIOI_API_KEY="YOUR_API_KEY"

Then quit the ChatGPT desktop app completely and open it again.

3. Edit config.toml

In the ChatGPT desktop app, open Settings > Configuration > Open config.toml and add the following. If the file already has content, merge it in:

model = "gpt-6-astra"
model_provider = "brioi"

[model_providers.brioi]
name = "Brioi"
base_url = "https://vip.brioi.com/v1"
wire_api = "responses"
env_key = "BRIOI_API_KEY"
supports_websockets = false

What each line does:

  • model: the default model.
  • model_provider: use the brioi provider defined below.
  • base_url: the endpoint. It must end in /v1, with /v1 only once.
  • wire_api = "responses": use the OpenAI Responses API. It’s the only value current Codex versions support.
  • env_key: the environment variable that holds the key.
  • supports_websockets = false: send requests over plain HTTP streaming rather than the Responses WebSocket transport.

Keep model and model_provider above the first [table] header. TOML assigns any key after a header to that table, so Codex won’t see them as top-level settings.

Save, then quit the ChatGPT desktop app completely and open it again.

4. Check that it works

Make sure you’re still signed in to ChatGPT, start a new task and send:

Reply with BRIOI_CODEX_OK only

When the reply arrives, check the request log in the Brioi console to confirm the request came through.

Codex CLI

1. Install

The official installer, on macOS and Linux:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

Windows, from a new PowerShell window:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

npm and Homebrew work too:

npm install -g @openai/codex
brew install --cask codex

Check the version:

codex --version

2. Set the environment variable

The CLI reads variables from the terminal it starts in. On macOS and Linux, add this line to ~/.zshrc (or ~/.bashrc for bash) and open a new terminal:

export BRIOI_API_KEY="YOUR_API_KEY"

On Windows, use the setx command from the desktop section above, then open a new terminal.

3. Write the config

The config file is ~/.codex/config.toml, or %USERPROFILE%\.codex\config.toml on Windows. Create it if it doesn’t exist and add the same content as the desktop app (step 3 above). The desktop app, CLI and IDE extension all read this one file.

Custom providers only work in this user-level file. Per OpenAI’s docs, a project’s .codex/config.toml ignores model_provider and model_providers and prints a warning at startup.

4. Run it

From your project folder:

codex

Run /status to confirm that the active provider is brioi, then send a test prompt and check that a reply comes back. Custom providers default to requires_openai_auth = false, so the CLI authenticates with the key in BRIOI_API_KEY rather than an OpenAI login.

Choosing a model

You can set model to any other GPT model in your key’s group. Which models a group has and what each costs is on the pricing page. For a live list, call GET https://vip.brioi.com/v1/models with your key.

Common errors

Symptom Fix
401 or API_KEY_REQUIRED Check that env_key is BRIOI_API_KEY. The desktop app needs a system-level variable or ~/.codex/.env, and a full quit and reopen after changes. Check that base_url is exactly https://vip.brioi.com/v1. Check that the key is enabled, the balance is fine and the group includes the model. Remove requires_openai_auth = true from [model_providers.brioi] if it’s there; with it set, Codex ignores env_key
Signed in to ChatGPT, but requests don’t go through Brioi Check that model_provider is brioi and sits above the first table header. Quit and reopen after saving
503 model_not_found The key’s group doesn’t include that model. Switch to a model the group has
401 again after a Mac restart launchctl setenv doesn’t survive a reboot. Run it again, or move the key to ~/.codex/.env
Settings in the project config have no effect model_provider only works in the user-level ~/.codex/config.toml

Keep your key safe

  • Don’t paste ChatGPT credentials, API keys or auth.json into group chats, screenshots, repositories or public logs.
  • Don’t commit shell profiles or .env files that contain keys.
  • If you think a key has leaked, disable it on the Brioi API keys page right away and create a new one.

FAQ

Can the Codex desktop app and CLI share one config?

Yes. Both read ~/.codex/config.toml. The difference is that the desktop app only sees system-level environment variables or ~/.codex/.env, not ones exported in your shell.

OpenAI doesn’t serve my country. Can I still use Codex?

With a custom provider, the Codex CLI runs on your Brioi key, which works in regions OpenAI doesn’t serve. Top up with USDT or an international card. The desktop app path above also expects a ChatGPT sign-in, so where ChatGPT accounts aren’t offered, the CLI is the simpler route.

Do I need ChatGPT Plus or Pro?

Not for the CLI with a custom provider. Usage is billed per token from your Brioi balance.

Does Claude Code work the same way?

Yes, with a different config. See Claude Code API key setup.