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-compatible API. 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 environment variables. Set these two, then pass a Tokun model ID:

bash
export OPENAI_BASE_URL="https://api.tokun.sh/v1"
export OPENAI_API_KEY="sk-..."      # your Tokun key
codex --model openai/gpt-5.3-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: environment variables (shell profile) or the Codex config.
- Protocol: OpenAI-compatible.

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. Set OPENAI_BASE_URL = https://api.tokun.sh/v1
2. Set OPENAI_API_KEY = <the user's Tokun sk- key>
3. Pass the model id (e.g. openai/gpt-5.3-codex) via --model or the config.
4. Never print, log, or commit the full key.

Verify:
1. Run: codex --model openai/gpt-5.3-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 lines for the user to run rather than refusing.

Set up manually

Prefer a config file? Codex also reads its config (for example, ~/.codex/config.toml). Set the OpenAI base URL and key there, or keep the two environment variables above. To roll back, unset OPENAI_BASE_URL / OPENAI_API_KEY or restore your provider config.

Model IDs

Pass any Tokun model ID in --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

Unlike the Anthropic API, the OpenAI base URL does include /v1. Use https://api.tokun.sh/v1. The key in OPENAI_API_KEY is your Tokun sk- key, not an OpenAI key.
SymptomLikely causeFix
401 / auth errorWrong or missing keyConfirm OPENAI_API_KEY is your Tokun sk- key.
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.