This guide covers two setup paths: the one-command script (macOS / Linux / Windows) and the official desktop app. Both write the same Codex configuration and can be used interchangeably.
The one-minute answer
Pointing Codex at this gateway takes three steps: get an API key (starts with sk-) → pick a model → write the gateway base URL and key into ~/.codex/config.toml. Both the one-command script and the desktop app do the last step for you, preserve unrelated parts of your existing config, and let you re-pick a model or restore at any time.
How to get an API key (sk-)
- Open and sign in at https://token.dingtaiyunteng.com
- Open the “API Keys” page in the left sidebar of the console
- Click “Create API key”, name it, and pick a group if needed
- Copy the full key starting with
sk-
The key is usually shown in full only once, so save it immediately. If you lose it, delete it and create a new one; the old key stops working right away.
Path 1: one-command script
Prerequisites: Codex CLI (npm install -g @openai/codex) or the ChatGPT desktop app installed and launched at least once (so ~/.codex exists).
macOS / Linux — paste and run:
bash <(curl -fsSL https://token.dingtaiyunteng.com/scripts/codex-opentokenrouter-setup.sh)Windows — run this in PowerShell:
irm https://token.dingtaiyunteng.com/scripts/codex-opentokenrouter-setup.ps1 | iexThen follow the prompts:
- Enter
1to install - Paste your API key (starts with
sk-) - Pick a number from the gateway's model list (choose
0to type a model name, or press Enter to usegpt-5.6)
The script first checks the key against /v1/models, then fetches the model list for you to choose from; if verification fails it asks whether to continue before writing anything (and you will type the model name manually).
Path 2: official desktop app
- Install the OpenTokenRouter desktop app from the download page
- Open the Setup page and select the Codex client
- Enter the gateway origin (https://token.dingtaiyunteng.com) and paste your API key
- Click “Test connection”; on success, pick a model from the fetched list
- Preview and click “Apply”; the app writes
~/.codex/config.tomlfor you
The desktop app stores your API key in the system keychain / credential manager and only writes an auth command into the config file, which is safer than embedding the key.
What the script does
- Backs up the current config to
~/.codex/backup-opentokenrouter/ - Writes
modelandmodel_provider = "opentokenrouter"at the top of~/.codex/config.toml - Appends
[model_providers.opentokenrouter]withbase_url = "https://token.dingtaiyunteng.com/v1",wire_api = "responses", and your key - Removes stale
opentokenrouter/profilesblocks while keeping everything else - Re-running lets you pick another model from the list to switch at any time
Verify it works
Run codex; the startup line should show model: gpt-5.6 (or whatever you chose). You can also run:
codex exec --model gpt-5.6 "hello"FAQ
Where do I get an API key? Sign in → console → “API Keys” → create a key → copy the sk- key.
Change model or key? Re-run the script and pick another model from the list, or re-apply in the desktop app; the original backup is never overwritten.
See an “Unknown model” warning? Codex only means the model is not in its built-in catalog; requests are still forwarded as-is, so what matters is what the gateway actually supports.
Restore? Re-run the command and choose 2; the backup is copied back and the backup folder is removed.
Security
The script only edits ~/.codex/config.toml locally and never sends your key anywhere except the gateway you chose. Before piping a remote script to bash (or irm | iex on Windows), make sure the URL and its contents come from a source you trust.