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
Option 1: one-click setup script (recommended)
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_KEYenvironment 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 | bashWindows
# Run in PowerShell (not Command Prompt)
irm https://tokenfunc.com/install/codex.ps1 | iexWhen 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
Install Codex
macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | shWindows
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"npm
npm install -g @openai/codexWrite the config file
Add the content below to the Codex config file. If the file already has content, note that the
modelandmodel_providerlines must come first, before any[...]section; otherwise they are read as fields of the section above them and ignored.macOS / Linux
~/.codex/config.tomlmodel = "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 = falseWindows
%USERPROFILE%.codex\config.tomlmodel = "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 = falseenv_keytells Codex to read the key from theTOKENFUNC_API_KEYenvironment variable, which you set next.- You can rename the provider (
tokenfunc), butopenai,ollamaandlmstudioare reserved.
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 ~/.zshrcWindows
# Saved permanently; open a new terminal afterwards setx TOKENFUNC_API_KEY "sk-xxxxxxxxxxxxxxxx"Start and verify
Open a new terminal, run
codexand type/status. Check that the provider istokenfuncand 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
modelin the config file. - To switch once, run
codex -m gpt-5, or type/modelin 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
| Symptom | Cause and fix |
|---|---|
wire_api = "chat" is no longer supported | Current Codex removed the chat protocol. Use wire_api = "responses" |
| 401 / missing key | The 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 |
| 404 | base_url is missing /v1 |
| Settings ignored, still talks to OpenAI | model_provider sits under a [...] section. Move it to the top of the file |
| Streaming stalls or stops halfway | A proxy is buffering the stream. Check the proxy or switch networks |
Other errors: see FAQ and troubleshooting.