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
Section titled “Install”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 | shWindows (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/codexbrew install --cask codexThe 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 --versionIf 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.
Before you start
Section titled “Before you start”- Codex CLI is installed.
- Your token’s group includes models that support the Responses endpoint type (see the pricing page).
Option 1: generate the config in the console (recommended)
Section titled “Option 1: generate the config in the console (recommended)”The console builds the config in your browser; your token never leaves it.
- Open the console API Keys page and choose Terminal Commands in the action menu of the token you want to use.
- 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.
- 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.tomlcontent to~/.codex/config.toml(merge it with what is there). The token appears only in the environment variable block, not inconfig.toml. - Or click Download config script to get
codex-config.sh(macOS / Linux) orcodex-config.ps1(PowerShell). The dialog shows how to run it:
chmod +x codex-config.sh && ./codex-config.shpowershell -ExecutionPolicy Bypass -File .\codex-config.ps1The 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 = trueCompatibility mode (codex login)
Section titled “Compatibility mode (codex login)”The dialog has a Compatibility mode (codex login) switch. When it is on:
config.tomlusesrequires_openai_auth = trueinstead ofenv_key, and Codex stores the token itself.- The token is saved with
codex login --with-api-key. The dialog has you runcodex logoutfirst, 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 theconfig.tomlbelow it. - In compatibility mode the downloaded script runs these steps in order: pre-checks, backup,
codex logout, writeconfig.toml,codex login --with-api-key. It asks for the token at run time (input hidden) and rolls back if interrupted.
Option 2: configure by hand
Section titled “Option 2: configure by hand”If you prefer not to use the dialog, follow these three steps.
1. Set the API key environment variable
Section titled “1. Set the API key environment variable”macOS / Linux (add it to ~/.bashrc or ~/.zshrc so it persists):
export OPENPALMLAB_API_KEY=sk-xxxxWindows 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.
2. Edit config.toml
Section titled “2. Edit config.toml”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_urlmust include/v1.env_keyis the name of the environment variable, not the token itself, so the token never appears in the config file.modelis a model name from the pricing page.
3. Check it works
Section titled “3. Check it works”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.
Common problems
Section titled “Common problems”| 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.