TokenRa
中文Get API Key

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:

SHELL
# 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 --version

Configure

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:

config.toml
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"
SettingWhat to put in
modelThe default model: a TokenRa model ID from the table below.
model_providerMust 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_urlhttps://tokenra.io/v1, with /v1.
wire_api"responses", the only value current Codex accepts: "chat" was removed.
env_keyThe 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:

SHELL
# 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.

config.toml
[model_providers.tokenra]
name = "TokenRa"
base_url = "https://tokenra.io/v1"
wire_api = "responses"
requires_openai_auth = true
auth.json
{
  "OPENAI_API_KEY": "sk-..."
}

Verify

Check the connection

SHELL
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.

ModelModel IDTask time (one run)
GLM-5.3glm-5.35 s
DeepSeek V4.1 Flashdeepseek-v4.1-flash6 s
DeepSeek V4.1 Flash 1017deepseek-v4.1-flash-10179 s
Qwen3.8 Maxqwen3.8-max16 s
Qwen3.8 Flashqwen3.8-flash19 s
GLM-5.3 Flashglm-5.3-flash21 s
MiniMax M3.1 Flashminimax-m3.1-flash21 s
Kimi K3kimi-k322 s
MiniMax M3minimax-m329 s
Kimi K3.1 Prokimi-k3.1-pro33 s
GLM models: no medium effort
GLM-5.3, GLM-5.3 Flash and GLM-5.3 FlashX reject model_reasoning_effort = "medium" with HTTP 400. Leave the setting out, as in the test above, or use "low" or "high".
Not suitable
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, or codex exec -m kimi-k3.1-pro "...".
  • For every session: change model in config.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.