Codex
Codex CLI
Run Codex with a 2api API key, without signing in to ChatGPT. You only change two files.
Before you start, create a key in a GPT group in the console (see Groups).
Install
Section titled “Install”Use the official installer. Pick the one for your system:
curl -fsSL https://chatgpt.com/codex/install.sh | shpowershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"npm install -g @openai/codexbrew install --cask codexAfter installing, run codex --version. If it prints a version number, you are set.
Configure
Section titled “Configure”-
Fully quit any running Codex, including the Codex extension in VS Code.
-
Write the API key. Create or edit
~/.codex/auth.json(on Windows,%USERPROFILE%\.codex\auth.json):~/.codex/auth.json {"OPENAI_API_KEY": "sk-your-key"}You can also write it with a command. The result is the same:
Terminal window printf 'sk-your-key' | codex login --with-api-key -
Edit
~/.codex/config.tomland put the lines below at the very start of the file, before any[...]section:~/.codex/config.toml model_provider = "sub2api"[model_providers.sub2api]name = "sub2api"base_url = "https://2api.dev/v1"wire_api = "responses"requires_openai_auth = true- To pin a model, add
model = "model-name"below the first line. Use the model name shown under Use Key in the console, or look it up with/v1/models. - Optional: add the line
model_catalog_url = "https://2api.dev/v1/models"under[model_providers.sub2api]. The/modellist in newer versions of Codex then shows the 2api models. If Codex shows an error at startup after you add it, delete the line.
- To pin a model, add
-
Go to your project directory and start it:
Terminal window cd your-projectcodexIn Codex, type
/status. If the provider showssub2apiand the address ishttps://2api.dev/v1, Codex is going through 2api.
Next steps
Section titled “Next steps”- To use it in VS Code or Cursor: Codex extension
- If you also want features that need a ChatGPT sign-in, such as the mobile app and official plugins: Codex with ChatGPT sign-in + API
- If you get an error: Codex FAQ