Skip to content

Codex CLI

Codex CLI lets you add custom model providers in its config file. OpenPalmLab provides an OpenAI Responses-compatible endpoint (/v1/responses), so the setup below is all you need.

Install Codex CLI first, then follow the steps below to connect it to the gateway.

macOS / Linux:

终端窗口
curl -fsSL https://chatgpt.com/codex/install.sh | sh

Windows (run in a new PowerShell window):

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

You can also use npm or Homebrew:

终端窗口
npm install -g @openai/codex
brew install --cask codex

The official docs also describe using WSL2 on Windows and installing with the Linux command inside WSL; WSL1 is no longer supported.

Verify the installation:

终端窗口
codex --version

If it prints a version number, you are set. (On first run the official tool prompts you to sign in; for our gateway you use the API key setup below instead.) See the official Codex CLI documentation for details.

  • Codex CLI is installed.
  • Your token’s group includes models that support the Responses endpoint type (see the pricing page).
Section titled “Option 1: generate the config in the console (recommended)”

The console builds the config in your browser; your token never leaves it.

  1. Open the console API Keys page and choose Terminal Commands in the action menu of the token you want to use.
  2. Pick the Codex CLI tab, then a model and your system (macOS / Linux, Windows CMD or PowerShell). The model list shows what this token can use.
  3. In the default mode, follow the two blocks in the dialog: set the environment variable in your terminal (current session only), then save the config.toml content to ~/.codex/config.toml (merge it with what is there). The token appears only in the environment variable block, not in config.toml.
  4. Or click Download config script to get codex-config.sh (macOS / Linux) or codex-config.ps1 (PowerShell). The dialog shows how to run it:
终端窗口
chmod +x codex-config.sh && ./codex-config.sh
终端窗口
powershell -ExecutionPolicy Bypass -File .\codex-config.ps1

The script backs up your existing config.toml before writing, and it contains no token. In the default mode it only writes config.toml; you still set the environment variable from the dialog’s block.

The generated config.toml looks like this (name is the site name; the model is the one you picked). It differs from Option 2 below in three ways: the provider is called newapi, the variable is NEWAPI_API_KEY, and it adds model_catalog_url (so Codex reads the model catalog from this site’s /v1/models) and a capabilities table:

model_provider = "newapi"
model = "YOUR_MODEL"
[model_providers.newapi]
name = "OpenPalmLab"
base_url = "https://api.openpalm.ai/v1"
wire_api = "responses"
env_key = "NEWAPI_API_KEY"
model_catalog_url = "https://api.openpalm.ai/v1/models"
[model_providers.newapi.capabilities]
cyber_access_programs = true

The dialog has a Compatibility mode (codex login) switch. When it is on:

  • config.toml uses requires_openai_auth = true instead of env_key, and Codex stores the token itself.
  • The token is saved with codex login --with-api-key. The dialog has you run codex logout first, then the login command that carries the token. This replaces Codex’s current sign-in, including a ChatGPT account login. If the command reports an error, do not save the config.toml below it.
  • In compatibility mode the downloaded script runs these steps in order: pre-checks, backup, codex logout, write config.toml, codex login --with-api-key. It asks for the token at run time (input hidden) and rolls back if interrupted.

If you prefer not to use the dialog, follow these three steps.

macOS / Linux (add it to ~/.bashrc or ~/.zshrc so it persists):

终端窗口
export OPENPALMLAB_API_KEY=sk-xxxx

Windows PowerShell (persists for the current user):

终端窗口
[Environment]::SetEnvironmentVariable("OPENPALMLAB_API_KEY", "sk-xxxx", "User")

Open a new terminal afterwards so the variable is picked up.

Edit ~/.codex/config.toml (on Windows, %USERPROFILE%\.codex\config.toml):

model_provider = "openpalmlab"
model = "YOUR_MODEL"
[model_providers.openpalmlab]
name = "OpenPalmLab"
base_url = "https://api.openpalm.ai/v1"
env_key = "OPENPALMLAB_API_KEY"
wire_api = "responses"
  • base_url must include /v1.
  • env_key is the name of the environment variable, not the token itself, so the token never appears in the config file.
  • model is a model name from the pricing page.
终端窗口
codex "list the files in this directory"

If you get a normal reply and see the request on the console’s Usage Logs page, you are set up.

Symptom Fix
Codex still asks you to log in Make sure model_provider is at the top level of the file (not under a [...] table) and matches the name in [model_providers.xxx].
401 The environment variable is not set. Run echo $OPENPALMLAB_API_KEY in the same terminal to check.
404 base_url is missing /v1.
Model not available Use a model the pricing page lists as supporting the Responses endpoint.

You can also manage Codex provider settings in a GUI with CC Switch. Similar clients: Claude Code, Gemini CLI, OpenCode.