OfficialOpenAI-compatibleOpenAI
Codex CLI
OpenAI's official terminal agent.
Codex uses the OpenAI-compatible API, so it can talk to more than api.openai.com. Use your OpenAI key directly, or declare a custom provider in the config file.
Setup steps
- 1
Install the CLI
Requires Node.js 18 or newer. Installs the global codex command.
bashnpm install -g @openai/codex - 2
Option A: use your OpenAI key
Set your key from the OpenAI platform. Reopen the terminal after setx on Windows.
bash / zshexport OPENAI_API_KEY="your-api-key"PowerShellsetx OPENAI_API_KEY "your-api-key" - 3
Option B: add a custom provider
Declare an OpenAI-compatible endpoint in the config file. env_key names the environment variable holding the key; wire_api = chat suits most third-party endpoints.
~/.codex/config.tomlmodel = "your-model-name" model_provider = "custom" [model_providers.custom] name = "Custom" base_url = "https://api.example.com/v1" env_key = "OPENAI_API_KEY" wire_api = "chat" - 4
Clear a stored ChatGPT login
Only if you signed in with ChatGPT before. This forces Codex to use your own key instead.
bashcodex logout - 5
Start coding
Run it inside your project folder and start giving instructions.
bashcodex
Tip: If you were signed in with ChatGPT, run codex logout first, then pick "Provide your own API key" on next launch so it uses your custom provider.
Pick a cheaper model or provider first, then plug its key and endpoint into the steps above. Compare prices · Browse providers