Codex CLI

What is Codex CLI?

Codex CLI is a local coding agent that runs in your terminal. It supports custom model providers, so teams can route Codex model calls through JoyToken for centralized API key control, model routing, policy checks, wallet limits, and usage attribution.

JoyToken exposes an OpenAI-compatible Chat Completions endpoint:

https://api-dev.joytokens.ai/openai/v1

Quick Start

Step 1: Install Codex CLI

Install Codex CLI by following the official Codex installation instructions for your environment.

Step 2: Create a JoyToken API key

Create a dedicated key for Codex, for example dev-codex-cli.

Recommended policy:

SettingRecommendation
ModelStart with auto
BudgetSmall daily or weekly cap
IP allowlistTeam workstation, office, or VPN egress
LogsKeep enabled for debugging

Step 3: Set your API key

~/.zshrc
$export JOY_TOKEN_API_KEY="jt_xxx"

Reload your shell:

$source ~/.zshrc

Step 4: Configure Codex for JoyToken

Codex reads ~/.codex/config.toml. Add a JoyToken provider:

~/.codex/config.toml
1model_provider = "joytoken"
2model = "auto"
3
4[model_providers.joytoken]
5name = "joytoken"
6base_url = "https://api-dev.joytokens.ai/openai/v1"
7env_key = "JOY_TOKEN_API_KEY"

Step 5: Start Codex

$cd /path/to/your/project
$codex

Model requests now route through JoyToken.

Configuration Reference

Core settings

SettingDescriptionExample
model_providerProvider used by Codex"joytoken"
modelJoyToken model key or router mode"auto"
base_urlJoyToken OpenAI-compatible base URL"https://api-dev.joytokens.ai/openai/v1"
env_keyEnvironment variable containing the API key"JOY_TOKEN_API_KEY"

Model values

ValueBehavior
autoJoyToken router selects a model within policy
Concrete model keyPins the request to a JoyToken model while still passing policy and wallet checks
API key fixed modelKey policy restricts or overrides requested models

Why use JoyToken with Codex CLI?

Central API key control

Create dedicated Codex keys, revoke them independently, and keep local development separate from production keys.

Budget and policy controls

Apply model, tier, IP, and budget policies before a coding session can spend credits.

Usage visibility

Track Codex usage in JoyToken Logs, Usage, and Billing by API key. Split keys by developer or workflow when you need cleaner attribution.

Model flexibility

Start with auto while evaluating quality and cost. Pin a model later for repeatable workflows.

Troubleshooting

SymptomCheck
401 UnauthorizedJOY_TOKEN_API_KEY is set and copied correctly
403 ForbiddenKey policy allows the current IP, tier, and model
402 Payment RequiredWallet balance, quota, or budget is sufficient
Model not foundUse auto or a model key from the JoyToken model catalog
No JoyToken logsConfirm model_provider = "joytoken" and base_url includes /openai/v1

Resources