Tool integration · OpenAI Responses
Use TokenRa in Codex CLI
Codex CLI is OpenAI's open-source coding agent for the terminal. It calls models through the OpenAI Responses API, and TokenRa can be added to it as a custom model provider in config.toml. The setup below was tested with Codex CLI 0.165.0 on October 29, 2026.
- Base URL
https://tokenra.io/v1- API format
- OpenAI Responses
- Config file
~/.codex/config.toml- Tested with
- Codex CLI 0.165.0
Before you start
Before you start
- A TokenRa API key: create an account, then add a key on the API Keys page of the console. Keys start with
sk-. - No OpenAI account: Codex does not need a ChatGPT login when it runs on TokenRa.
Install
Install Codex CLI
Use OpenAI's installer, npm or Homebrew:
# macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Windows PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
# npm or Homebrew
npm install -g @openai/codex
brew install --cask codex
# Check the installation
codex --versionConfigure
Add TokenRa as a model provider
Codex reads ~/.codex/config.toml (on Windows %USERPROFILE%\.codex\config.toml). Create the file if it does not exist and add:
model = "deepseek-v4.1-flash"
model_provider = "tokenra"
web_search = "disabled"
[model_providers.tokenra]
name = "TokenRa"
base_url = "https://tokenra.io/v1"
wire_api = "responses"
env_key = "TOKENRA_API_KEY"| Setting | What to put in |
|---|---|
model | The default model: a TokenRa model ID from the table below. |
model_provider | Must match the name of the [model_providers.tokenra] table. |
web_search | "disabled". Otherwise Codex adds OpenAI's hosted web search tool to every request, and MiniMax M3.1 Flash rejects such requests with HTTP 400. |
base_url | https://tokenra.io/v1, with /v1. |
wire_api | "responses", the only value current Codex accepts: "chat" was removed. |
env_key | The environment variable that holds your TokenRa key. |
Store the key
Put your key in the TOKENRA_API_KEY environment variable, then open a new terminal:
# macOS / Linux: add this line to ~/.zshrc or ~/.bashrc
export TOKENRA_API_KEY="sk-..."
# Windows PowerShell: saved for your user
[Environment]::SetEnvironmentVariable("TOKENRA_API_KEY", "sk-...", "User")Alternative: keep the key in auth.json
Replace the env_key line with requires_openai_auth = true and save the key in ~/.codex/auth.json. Codex also keeps a ChatGPT sign-in in that file, so if you use one, stay with env_key.
[model_providers.tokenra]
name = "TokenRa"
base_url = "https://tokenra.io/v1"
wire_api = "responses"
requires_openai_auth = true{
"OPENAI_API_KEY": "sk-..."
}Verify
Check the connection
codex exec --skip-git-repo-check "Reply with OK if you can read this."codex exec runs one task and exits; --skip-git-repo-check lets it run outside a Git repository. codex on its own opens the interactive interface. A warning such as Model metadata for `deepseek-v4.1-flash` not found is expected: Codex has no built-in data for TokenRa model IDs and falls back to defaults.
Models
Tested models
On 2026-10-29 every model below finished the same task in Codex CLI 0.165.0 with the configuration above: read a file through the shell tool, then write a new file. Times are for the whole task in one run.
| Model | Model ID | Task time (one run) |
|---|---|---|
| GLM-5.3 | glm-5.3 | 5 s |
| DeepSeek V4.1 Flash | deepseek-v4.1-flash | 6 s |
| DeepSeek V4.1 Flash 1017 | deepseek-v4.1-flash-1017 | 9 s |
| Qwen3.8 Max | qwen3.8-max | 16 s |
| Qwen3.8 Flash | qwen3.8-flash | 19 s |
| GLM-5.3 Flash | glm-5.3-flash | 21 s |
| MiniMax M3.1 Flash | minimax-m3.1-flash | 21 s |
| Kimi K3 | kimi-k3 | 22 s |
| MiniMax M3 | minimax-m3 | 29 s |
| Kimi K3.1 Pro | kimi-k3.1-pro | 33 s |
model_reasoning_effort = "medium" with HTTP 400. Leave the setting out, as in the test above, or use "low" or "high".gemini-3.8-flash cannot be used here: its upstream rejects every request that carries tool definitions (HTTP 400), and coding agents send tools with every request.Switch
Switch models
- For one session or task:
codex -m kimi-k3.1-pro, orcodex exec -m kimi-k3.1-pro "...". - For every session: change
modelinconfig.toml.
FAQ
FAQ
wire_api = "chat" is no longer supported
Current Codex only speaks the Responses API. Set wire_api = "responses": TokenRa serves it at https://tokenra.io/v1/responses.
HTTP 400 about web search
An error such as 该模型暂不支持服务端联网搜索 (the model does not support server-side web search) means the request carried Codex's web search tool. Add web_search = "disabled" at the top of config.toml.
HTTP 400 invalid_request with a GLM model
Remove model_reasoning_effort = "medium" or change it to "low" or "high".
HTTP 401, or Codex asks me to sign in with ChatGPT
Codex is not using the TokenRa key. Check that config.toml is in ~/.codex, that model_provider is "tokenra", and that TOKENRA_API_KEY is set in the terminal you start Codex from. Open a new terminal after setting the variable.
Where can I see usage and cost?
Every request is listed under Usage Logs in the console, with its model, tokens and cost. Live rates are on the Model Square.