Set up Codex CLI
Codex CLI is OpenAI's official terminal AI coding tool, with support for custom model providers.
Install
bash
npm install -g @openai/codexConfigure
Edit ~/.codex/config.toml (create it if it doesn't exist):
toml
model = "gpt-5.1" # example; available models are as shown in the Model Square
model_provider = "treenew"
[model_providers.treenew]
name = "树新在线"
base_url = "https://api.treenew.online/v1"
env_key = "TREENEW_API_KEY"
wire_api = "chat"Then set the token environment variable (add it to ~/.zshrc or ~/.bashrc):
bash
export TREENEW_API_KEY="sk-your-token"Verify
bash
codex "write a quicksort in Python"If it outputs code normally, the setup succeeded.
Notes
wire_api = "chat"means it uses the/v1/chat/completionscompatible endpoint, which has the broadest compatibility- Switch models: change the
modelfield inconfig.toml, or usecodex -m model-nameat runtime - 401 error: check that
TREENEW_API_KEYhas been exported (echo $TREENEW_API_KEY)