Skip to content

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/codex

Configure

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/completions compatible endpoint, which has the broadest compatibility
  • Switch models: change the model field in config.toml, or use codex -m model-name at runtime
  • 401 error: check that TREENEW_API_KEY has been exported (echo $TREENEW_API_KEY)

Home · Console