Codex

Add a custom model provider in config.toml so the Codex CLI uses this site.

Codex is OpenAI's official command-line coding agent and only speaks the OpenAI Responses protocol. Connect it by adding a custom model provider to its config file.

  • Protocol: OpenAI Responses (/v1/responses)
  • Base URL: https://tokenfunc.com/v1 (with /v1)
  • Models: the GPT family, for example gpt-5

Run the command below in a terminal, paste your key and pick a default model when asked. The script:

  • Checks the key against the model list endpoint (free of charge)
  • Installs Codex the official way if it is missing
  • Adds this site as a model provider in ~/.codex/config.toml, keeping your other settings and backing up the original file
  • Saves the key as the TOKENFUNC_API_KEY environment variable: in your shell startup file on macOS / Linux, as a user environment variable on Windows

macOS / Linux

curl -fsSL https://tokenfunc.com/install/codex.sh | bash

Windows

# Run in PowerShell (not Command Prompt)
irm https://tokenfunc.com/install/codex.ps1 | iex

When it finishes, open a new terminal (the key variable only applies to new terminals), then jump to the "Start and verify" step below.

Option 2: one-click import with CC Switch

With CC Switch installed, click the button below, make sure Codex is selected in the dialog and pick a model.

Enable the imported provider in CC Switch, then skip to the verify step below.

Option 3: manual setup

  1. Install Codex

    macOS / Linux

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

    Windows

    powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

    npm

    npm install -g @openai/codex
  2. Write the config file

    Add the content below to the Codex config file. If the file already has content, note that the model and model_provider lines must come first, before any [...] section; otherwise they are read as fields of the section above them and ignored.

    macOS / Linux

    ~/.codex/config.toml
    model = "gpt-5"
    model_provider = "tokenfunc"
    
    [model_providers.tokenfunc]
    name = "tokenfunc"
    base_url = "https://tokenfunc.com/v1"
    env_key = "TOKENFUNC_API_KEY"
    wire_api = "responses"
    requires_openai_auth = false

    Windows

    %USERPROFILE%.codex\config.toml
    model = "gpt-5"
    model_provider = "tokenfunc"
    
    [model_providers.tokenfunc]
    name = "tokenfunc"
    base_url = "https://tokenfunc.com/v1"
    env_key = "TOKENFUNC_API_KEY"
    wire_api = "responses"
    requires_openai_auth = false
    • env_key tells Codex to read the key from the TOKENFUNC_API_KEY environment variable, which you set next.
    • You can rename the provider (tokenfunc), but openai, ollama and lmstudio are reserved.
  3. Set the key as an environment variable

    Codex recommends keeping the key out of the config file and in an environment variable.

    macOS / Linux

    # Save it in your shell profile so new terminals get it too (bash users: ~/.bashrc instead of ~/.zshrc)
    echo 'export TOKENFUNC_API_KEY="sk-xxxxxxxxxxxxxxxx"' >> ~/.zshrc
    source ~/.zshrc

    Windows

    # Saved permanently; open a new terminal afterwards
    setx TOKENFUNC_API_KEY "sk-xxxxxxxxxxxxxxxx"
  4. Start and verify

    Open a new terminal, run codex and type /status. Check that the provider is tokenfunc and the model is the one you set. Then send "Reply with exactly: ok"; a reply means you are connected.

    Screenshot pendingThe /status output in Codex showing the tokenfunc provider and the current modeltools/codex-status.png

Choosing and switching models

  • The default model comes from model in the config file.
  • To switch once, run codex -m gpt-5, or type /model in a session.
  • Codex relies on the Responses endpoint and tool calling. Some non-OpenAI models may not fully support them; if something looks wrong, switch back to a GPT model first.

Troubleshooting

SymptomCause and fix
wire_api = "chat" is no longer supportedCurrent Codex removed the chat protocol. Use wire_api = "responses"
401 / missing keyThe variable did not reach Codex. Open a new terminal after setting it; the Codex desktop app does not see variables exported in a terminal, so use the permanent form above
404base_url is missing /v1
Settings ignored, still talks to OpenAImodel_provider sits under a [...] section. Move it to the top of the file
Streaming stalls or stops halfwayA proxy is buffering the stream. Check the proxy or switch networks

Other errors: see FAQ and troubleshooting.