Tokun

Use Tokun with Codex CLI

Use Tokun as the OpenAI-compatible backend for Codex CLI — the same Codex workflow you already use, billed at Tokun pricing with Tokun's model routing.

What this connects

Use Tokun as the OpenAI-compatible backend for Codex CLI — the same Codex workflow you already use, billed at Tokun pricing with Tokun's model routing.

Before you start

  • A Tokun API key (starts with sk-) from the console.
  • A funded Tokun balance.
  • Codex CLI installed and working.
  • A chosen model id, e.g. openai/gpt-5.3-codex.

Recommended quickstart

Codex reads its provider from environment variables — set two and 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

Copy for AI agent

Working inside an AI coding agent? The shortest path is one line — paste this and your agent reads the full machine-readable guide at /llms.txt and does the Codex CLI setup itself. You only supply your key:

text
Read https://tokun.sh/llms.txt and integrate Tokun into this project.
Want a fully-specified, deterministic block instead (exact steps, idempotent, fail-closed)? Paste the one below — it configures 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.

Manual configuration

Prefer a config file? Codex also reads its config (e.g. ~/.codex/config.toml) — set the OpenAI base URL + key there, or keep the two env vars above. To roll back, unset OPENAI_BASE_URL / OPENAI_API_KEY (or restore your provider config).

Model naming

Pass any Tokun model id in --model (the lab/model convention), e.g. openai/gpt-5.3-codex or openai/gpt-5.5. Codex sends the bare id too (gpt-5.3-codex) — Tokun resolves both. An unknown id returns an error, never a substituted model.

Verify & troubleshoot

Unlike the Anthropic surface, 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 in the console.
Connection errorMissing /v1 on the base URLUse https://api.tokun.sh/v1 — the OpenAI surface keeps /v1.
Unknown model errorModel id not recognizedUse a lab/model id, e.g. openai/gpt-5.3-codex.