Just 3 minutes, connect RuToken to Codex in one click

No file editing, no environment variables, no technical knowledge. Copy the prompt below, paste it to Codex, and it does the rest.

About 3 minutes Fully automatic No terminal needed

Three things to check first

If you have all three, skip straight to step 1.

  • 1
    Codex is installed and opensIf you have not installed it yet, follow the official Codex instructions first.
  • 2
    You have a RuToken API keyA long string starting with sk-. Create or copy one from the Tokens page of your dashboard.
  • 3
    You can open Codex's chat boxThe input field where you normally ask questions. That is the only place you need to use.
1

Copy your API key

Log in to the RuToken dashboard, open the Tokens page and copy your key (starts with sk-). If you do not have one, create it there.

Paste it into a scratch note for a moment — you will need it in the next step. Make sure there are no leading or trailing spaces.
2

Copy the prompt below and fill in your key

Click Copy at the top right, paste it somewhere editable, and replace the key placeholder with your key.

prompt.txt
I want to connect the  RuToken API to Codex. I am not technical, so please figure everything out yourself and do not ask me technical questions. Just explain the result in plain language when you are done.

── My details ────────────────────────────
 RuToken API key: <paste your key here>
Preferred model: <leave blank if unsure, pick one for me>
──────────────────────────────────────

Please follow these 6 steps exactly:

[STEP 1] Check the environment
Run codex --version and note the version number.
Locate the config file:
  macOS / Linux → ~/.codex/config.toml
  Windows       → %USERPROFILE%\\.codex\\config.toml

[STEP 2] Back up first
If config.toml already exists, make a backup copy with today's date in the filename (e.g. config.toml.bak-20261012).
If the folder or file does not exist, create it.

[STEP 3] Verify the key BEFORE touching any config
Use curl to call https://rutoken.ai/v1/models with the header: Authorization: Bearer <my key>

  Works        → show me the list of available model names (names only, do not paste raw JSON)
  401 or 403   → stop and tell me "the key is invalid, please copy it again from the  RuToken dashboard". Do not modify the config.
  Network down → tell me the exact error. Do not modify the config.

Never print the key to the output and never write it into any log or temporary file.

[STEP 4] Pick a model and actually test it
Choose a model suitable for coding from the list in step 3, preferring the gpt-5 family.
Then test it with a minimal curl request to https://rutoken.ai/v1/responses:
  body: {"model":"<model name>","input":"hi"}
If it errors (model not found, endpoint unsupported, etc.), try the next one in the list, up to 3 attempts.
Tell me which model finally worked.

[STEP 5] Write the config
Write parts A and B below into config.toml. Three hard requirements:

  (a) Part A contains TOP-LEVEL keys. They must go at the very beginning of the file, before any [bracketed] section.
      If they end up after a [section] header they are silently ignored and Codex quietly falls back to
      the official endpoint — this is the single most common cause of failure.
  (b) Part B goes at the very end of the file.
  (c) Keep all existing content intact (e.g. [tui], [mcp_servers]). If the file already contains model or
      model_provider lines, only change their values — never write them twice. Duplicate keys make Codex
      fail to start.

  ── A: at the very top of the file ──
model = "<the model name from step 4>"
model_provider = "newapi"

  ── B: at the very end of the file ──
[model_providers.newapi]
name = " RuToken"
base_url = "https://rutoken.ai/v1"
wire_api = "responses"
experimental_bearer_token = "<my key>"

Three things to be careful about:
  · base_url must be exactly https://rutoken.ai/v1 — do not append /responses (Codex adds it)
  · wire_api must be "responses". Setting "chat" makes Codex fail to start
  · Do not rename or add any of these fields. A misspelled field is ignored without an error

[STEP 6] Self-check and report back
Run codex doctor and confirm the Configuration and auth sections are healthy, especially:
  config.toml parse   ok
  wire API            responses

Then tell me four things:
  1) The full path of config.toml on my machine
  2) Which model is now configured
  3) This reminder: "Completely quit Codex and reopen it for the new config to take effect"
  4) If doctor reports any fail or warn, explain in plain language what the problem is and what I should do

Please do not show me code or JSON at any point.
Note: this prompt appears in your conversation with Codex, so the key is sent once. The risk is low for the service you already use. If you would rather not, create a fresh key after setup and swap it in.
3

Paste the whole thing to Codex and wait

Open Codex, paste the whole block into the input field and press Enter. It will then do everything in front of you: back up, verify the key, pick a model, test it, write the config, self-check.

If it asks you something, just answer. Normally it will finish on its own without interrupting you.
4

Completely quit Codex and reopen it

Do not skip this. Codex reads the config only at startup. On macOS press ⌘Q; on Windows make sure nothing is left in the system tray.

After restarting, this means success
OpenAI Codex v0.161.0
--------
model:    gpt-5.6-terra      ← this should show a gateway model
provider: newapi            ← must say newapi, not openai
--------
As long as provider says newapi and model shows your chosen model, you are connected. Just use it normally from there.

Troubleshooting

Check here first — most issues are in these eight answers.

It says my key is invalid. What now?

Go back to the Tokens page in the dashboard and copy it again. The usual causes are a trailing space or newline, a key that was deleted or disabled, or a key from a different platform.

Then paste the new key to Codex and let it retry.

After restarting nothing changed — it did not take effect

Nine times out of ten the model and model_provider lines are in the wrong place.

They must be at the very top of the file. If they end up after a bracketed section such as [tui], Codex does not error — it silently ignores them and falls back to the official endpoint, which looks exactly like "nothing happened".

Startup error: wire_api "chat" is no longer supported

Many older tutorials still say wire_api = "chat". New Codex versions reject it.

Change it to wire_api = "responses" and it will start. The prompt we provide already uses the right value.

Error: Missing environment variable

That means the config uses the older "read from environment variable" approach, but the variable is not set.

Our prompt avoids this entirely — it writes the key directly as experimental_bearer_token, so no environment variable is needed.

Do I still need to log in with a ChatGPT account?

No. requires_openai_auth defaults to off, so Codex goes entirely through the gateway and never touches the official endpoint.

Any existing login is left untouched — to go back to official later, just revert the config.

How do I switch models later?

Change the model value on the first line of the config file, then completely quit and reopen Codex.

Or simpler: tell Codex "change model in config.toml to xxx and remind me to restart".

How do I revert / restore my old setup?

Codex made a backup for you before configuring, named like config.toml.bak-20261012 in the same folder. Rename it back to config.toml (overwriting the current one) and you are restored.

Is my key safe?

The key is stored in plain text in config.toml on your machine. That is standard for custom providers in Codex.

Do not send that file to anyone and do not commit it to a public repository. If it leaks, delete the old key in the dashboard, create a new one, and update only the experimental_bearer_token line.

Prefer to do it by hand?

If you would rather edit the file yourself, paste the block below. Location: macOS / Linux is ~/.codex/config.toml, Windows is %USERPROFILE%\.codex\config.toml.

~/.codex/config.toml
model = "gpt-5.6-terra"
model_provider = "newapi"

# NOTE: model and model_provider are TOP-LEVEL keys and must come
# before any [section] header, otherwise they are silently ignored

[model_providers.newapi]
name = " RuToken"
base_url = "https://rutoken.ai/v1"
wire_api = "responses"
experimental_bearer_token = "put your key here"
Remember to completely quit and reopen Codex afterwards.