Skip to main content
Use this guide to run Codex CLI with CometAPI as a model provider. Official references:
Model availability changes frequently. The examples below use your-model-id — replace it with a current coding-friendly model ID from the CometAPI Models page.

Prerequisites

RequirementDetails
OSmacOS 12+, Linux (Ubuntu 20.04+ / Debian 10+), or Windows 11 via WSL2
Node.js22+ (LTS recommended)
Git2.23+ recommended
CometAPI keyGet one from CometAPI Dashboard (starts with sk-)

Install Codex CLI

npm i -g @openai/codex
Or via Homebrew:
brew install --cask codex
Verify the installation:
codex --version

Configure CometAPI

There are two ways to point Codex at CometAPI. Choose whichever fits your workflow.
The easiest option — redirect the built-in OpenAI provider to CometAPI with a single line. No need to define a custom provider.Create ~/.codex/config.toml:
model = "your-model-id"
openai_base_url = "https://api.cometapi.com/v1"

Store your API key

Create ~/.codex/auth.json:
{
  "OPENAI_API_KEY": "sk-your-cometapi-key"
}
Replace sk-your-cometapi-key with your actual CometAPI key.
This file is mandatory. Without a valid OPENAI_API_KEY entry in auth.json, Codex exits with API key auth is missing a key.

Start Codex

cd your-project
codex
On first launch, Codex prompts you to choose a theme and confirm safety settings.

Override model per session

Switch to a different model for a single run without editing config.toml:
codex --model your-model-id

Alternative: environment variable

Instead of auth.json, export the key directly:
export OPENAI_API_KEY="sk-your-cometapi-key"
codex
This sets the key for the current terminal session only. For persistence, add the export line to ~/.zshrc or ~/.bashrc.

Troubleshooting

SymptomFix
API key auth is missing a keyEnsure ~/.codex/auth.json contains "OPENAI_API_KEY": "sk-..."
Login prompt appears unexpectedlyDelete stale ~/.codex/auth.json and recreate it with your CometAPI key
Model not foundCheck the Models page for currently available models
Connection timeoutConfirm openai_base_url or base_url is https://api.cometapi.com/v1 in config.toml
Windows issuesCodex requires WSL2 on Windows — native CMD/PowerShell is not supported