Skip to content
2api2api Docs
Open console

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).

Use the official installer. Pick the one for your system:

Terminal window
curl -fsSL https://chatgpt.com/codex/install.sh | sh

After installing, run codex --version. If it prints a version number, you are set.

  1. Fully quit any running Codex, including the Codex extension in VS Code.

  2. 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
  3. Edit ~/.codex/config.toml and 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 /model list in newer versions of Codex then shows the 2api models. If Codex shows an error at startup after you add it, delete the line.
  4. Go to your project directory and start it:

    Terminal window
    cd your-project
    codex

    In Codex, type /status. If the provider shows sub2api and the address is https://2api.dev/v1, Codex is going through 2api.