Codex CLI
Connect OpenAI's local coding agent Codex CLI to RuToken through a custom model provider.
Codex CLI is OpenAI's coding agent that runs locally in your terminal (GitHub). It edits files, runs commands under sandbox and approval policies and uses the OpenAI Responses API, which RuToken supports at https://rutoken.ai/v1/responses.
Prefer a guided setup? The /codex-setup page generates the configuration and commands for your system in one click.
Prerequisites
- An API key: open the console, go to API Keys and create a dedicated key (for example, named
Codex) with access to the models you plan to use. - Node.js 22 or newer (for the npm installation), or Homebrew on macOS.
- On Windows, native support is available; OpenAI also recommends WSL2 for the best experience.
Installation
npm install -g @openai/codex
brew install --cask codex
Check the installation:
codex --version
Configuration
1. Edit config.toml
Open the Codex configuration file (create the folder and the file if they do not exist):
| OS | Path |
|---|---|
| macOS / Linux | ~/.codex/config.toml |
| Windows | %USERPROFILE%\.codex\config.toml |
Merge the following. model and model_provider must be at the top level, before any [section]:
model = "gpt-5-codex" # replace with a model ID from the Model Square
model_provider = "newapi"
[model_providers.newapi]
name = " RuToken"
base_url = "https://rutoken.ai/v1"
env_key = "NEWAPI_API_KEY"
wire_api = "responses"
| Key | Value |
|---|---|
base_url |
https://rutoken.ai/v1 — Codex appends /responses |
env_key |
name of the environment variable that holds your key |
wire_api |
keep "responses" |
2. Set the API key
export NEWAPI_API_KEY="sk-xxxx"
# To keep it, add the same line to ~/.zshrc or ~/.bashrc
$env:NEWAPI_API_KEY = "sk-xxxx"
# To keep it for new terminals:
setx NEWAPI_API_KEY "sk-xxxx"
$env: only lasts for the current window, and setx only affects windows opened afterwards. Start codex from a terminal where the variable is set.
Verify
cd /path/to/your/project
codex
Choose the approval mode when asked, then send Only reply "Connection successful". Do not read or write files or run commands. You can also test non-interactively:
codex exec "Reply with OK"
Use /model inside Codex to switch models. Each request appears in the console under Usage Logs.
Troubleshooting
| Symptom | Fix |
|---|---|
NEWAPI_API_KEY is missing |
Launch codex from the terminal where the variable is set; env_key must match the variable name exactly. |
401 / invalid API key |
Copy the full key again; check that it is enabled, not expired and has quota left, then set the variable again. |
404 / Responses not supported |
base_url must end with /v1, and wire_api must be "responses". Make sure the chosen model supports the Responses API. |
| Model not found | Replace model with an ID from the Model Square and check the key's model limits. |
| Another provider is still used | Put model and model_provider at the top of the file; check whether a profile or project-level config overrides them. |