All guides

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.

Official docs

Setup steps

  1. 1

    Install the CLI

    Requires Node.js 18 or newer. Installs the global codex command.

    bash
    npm install -g @openai/codex
  2. 2

    Option A: use your OpenAI key

    Set your key from the OpenAI platform. Reopen the terminal after setx on Windows.

    bash / zsh
    export OPENAI_API_KEY="your-api-key"
    PowerShell
    setx OPENAI_API_KEY "your-api-key"
  3. 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.toml
    model = "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. 4

    Clear a stored ChatGPT login

    Only if you signed in with ChatGPT before. This forces Codex to use your own key instead.

    bash
    codex logout
  5. 5

    Start coding

    Run it inside your project folder and start giving instructions.

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