Use Tokun with Codex CLI

Connect Codex CLI to Tokun using your API key and a supported model.

Overview

Codex CLI connects to Tokun's OpenAI Responses API through a provider in its config file. Your Codex workflow stays the same, and requests use Tokun's pricing and model routing.

Before you start

  • A Tokun API key (starts with sk-) from the API keys page.
  • A funded Tokun balance.
  • Codex CLI, installed and working.
  • A model ID, such as openai/gpt-5.3-codex.

Quickstart

Codex reads its provider from ~/.codex/config.toml. Add this to the file (the first three lines go before any [section]):

toml
model = "openai/gpt-5.3-codex"
model_provider = "tokun"
web_search = "disabled"

[model_providers.tokun]
name = "Tokun"
base_url = "https://api.tokun.sh/v1"
env_key = "TOKUN_API_KEY"
wire_api = "responses"

Then put your Tokun key in the environment and start Codex:

bash
export TOKUN_API_KEY="sk-..."      # your Tokun key
codex

Set up with an AI assistant

Paste this prompt into your AI coding agent. It reads the setup guide at /llms.txt and sets up Codex CLI for you. You only need to provide your API key.

text
Read https://tokun.sh/llms.txt and integrate Tokun into this project.
Prefer exact, step-by-step instructions? Paste this detailed prompt instead. It sets up Codex CLI specifically.
text
You are configuring Codex CLI to use Tokun.

Scope:
- OS: macOS or Linux.
- Config: the Codex config file, ~/.codex/config.toml, plus the TOKUN_API_KEY environment variable.
- Protocol: OpenAI Responses.

Tokun values:
- API key placeholder: TOKUN_API_KEY_HERE  (a Tokun key starts with sk-)
- Base URL: https://api.tokun.sh/v1
- Recommended model: openai/gpt-5.3-codex

Apply:
1. Back up ~/.codex/config.toml if it exists. Keep MCP servers, profiles and every other setting.
2. Before the first [section], set: model = "openai/gpt-5.3-codex"; model_provider = "tokun"; web_search = "disabled"
3. At the end of the file, add (or update) this section:
[model_providers.tokun]
name = "Tokun"
base_url = "https://api.tokun.sh/v1"
env_key = "TOKUN_API_KEY"
wire_api = "responses"
4. Set TOKUN_API_KEY = <the user's Tokun sk- key> in the shell profile. Never write the key into config.toml.
5. Do not set OPENAI_BASE_URL or OPENAI_API_KEY for Codex: Codex does not send its requests to OPENAI_BASE_URL, so a key there reaches OpenAI, not Tokun.
6. Never print, log, or commit the full key.

Verify:
1. Run: codex "say hello in one word"
2. On 401 check the key; on 402 top up the balance; on an unknown-model error check the id.

If you are configuring the shell you are running in, the env change applies to NEW processes — start a fresh Codex invocation. If you cannot safely edit the profile, OUTPUT the exact export line for the user to run rather than refusing.

Set up manually

The provider block keeps your key out of the file: Codex reads it from TOKUN_API_KEY. web_search = "disabled" is required: Codex sends its web search tool by default, and Tokun's Responses API does not support it yet. To roll back, delete the [model_providers.tokun] section and the three top lines, or restore your backup.

Model IDs

Set any Tokun model ID as model in the config, or pass it with --model, using lab/model format, such as openai/gpt-5.3-codex or openai/gpt-5.5. Codex also sends the bare ID (gpt-5.3-codex); Tokun resolves both. An unknown ID returns an error and is never swapped for a different model.

Official model pools

Official model pools appear in the model catalog and use a pool ID such as flash-pool. Choose an available pool from the live catalog; pool names and members are configured by Tokun administrators.

When the pool enables member selection, use pool-id/member-name, replacing the model's lab prefix with the pool ID. The selected member is the only model that can execute; the pool's pricing mode still applies. When selection is disabled, this form returns 400.

  • Fixed token pricing uses the pool's input, output, cache and context-tier rates for every member, including a member you select yourself.
  • Actual model pricing uses the serving member's price, frozen before the request. A retry to another member uses that member's frozen price.
  • Fixed per-request pricing charges once after an upstream success response begins. Missing usage, a partial response or a client disconnect after that point still counts once. Failures before success and unsuccessful retries do not add charges.

Use a pool that lists the API format this client sends. Model pool settings in the live catalog control which members are shown and whether member selection is available.

Troubleshooting

Codex does not use OPENAI_BASE_URL: with only that variable and OPENAI_API_KEY set, Codex sends its requests to OpenAI and fails with OpenAI's 401 "Missing bearer or basic authentication in header". Use the provider block above. Its base_url is https://api.tokun.sh/v1, with /v1, and TOKUN_API_KEY holds your Tokun sk- key.
SymptomLikely causeFix
401 mentioning api.openai.comCodex is calling OpenAI, not TokunUse the [model_providers.tokun] block and model_provider = "tokun"; Codex ignores OPENAI_BASE_URL.
401 / auth error from TokunWrong or missing keyConfirm TOKUN_API_KEY holds your Tokun sk- key, in the shell that starts Codex.
400 web_search is not supportedCodex sent its web search toolAdd web_search = "disabled" at the top of config.toml.
402 / payment requiredEmpty Tokun balanceTop up on the Billing page.
Connection errorMissing /v1 on the base URLUse https://api.tokun.sh/v1. The OpenAI base URL keeps /v1.
Unknown model errorModel ID not recognizedUse a lab/model ID, such as openai/gpt-5.3-codex.