📚 目录 / Contents

OpenAI Codex

Use TokenHub with OpenAI Codex (CLI and Desktop)

OpenAI Codex is OpenAI’s AI programming assistant, available as both a command-line tool (CLI) and desktop application, with support for the latest models like GPT-5.5.

ℹ️ Note: Codex CLI uses OpenAI’s new Responses API protocol (/v1/responses), while the desktop app uses standard Chat Completions API. This guide covers both versions.


Option 1: Codex Desktop Configuration

Codex Desktop requires manual configuration file editing. After configuration, you must completely quit and restart the application.

Setup Steps

1. Locate Codex Configuration Directory

Windows:

C:\Users\{username}\.codex

macOS:

~/.codex

2. Configure API Key

Find the auth.json file and modify the OPENAI_API_KEY field:

{
  "OPENAI_API_KEY": "sk-xxxxx"
}

Replace sk-xxxxx with your TokenHub API Key

3. Configure Custom API Provider

Find the config.toml file and add the following configuration:

# Specify custom API provider
model_provider = "my_custom_api"

# Default model name
model = "gpt-5.1"

# Reasoning effort level (optional)
model_reasoning_effort = "high"

# Define custom API provider
[model_providers.my_custom_api]
name = "my_custom_api"

# TokenHub API endpoint
base_url = "https://hubwave.ai/v1"

# API protocol type
wire_api = "responses"

📝 Notes:

  • Replace base_url with your actual TokenHub domain
  • model can be changed to any model name configured in TokenHub
  • wire_api must be set to "responses"

4. Completely Quit and Restart Codex

Important: You must completely quit the application, not just log out!

  • Windows: Right-click system tray icon → Quit, or use Task Manager to end process
  • macOS: Right-click Dock icon → Quit, or use Cmd+Q to quit completely

⚠️ Warning: Simply clicking the window close button (X or red close button) may not fully quit the application. Codex may continue running in the background. You must quit from the system tray/Dock.

5. Reopen Codex

After completely quitting, restart the Codex desktop application for the configuration to take effect.

Usage

  • After configuration, Codex will automatically use TokenHub’s API
  • All models configured in your TokenHub dashboard are available
  • All features (Chat, Composer, Cmd+K) will use your custom API

Option 2: Codex CLI Configuration

Codex CLI is suitable for developers who prefer command-line workflows, offering more flexibility with slightly more complex setup.

Prerequisites

  • Codex CLI v0.142.5 or higher
  • TokenHub API Key (format: sk-xxxxx)
  • Windows users: PowerShell or CMD

Setup Steps

1. Set Environment Variable

For security, Codex requires storing the API key in an environment variable instead of the config file.

Windows (PowerShell):

# Set permanent environment variable
[System.Environment]::SetEnvironmentVariable('MY_CUSTOM_API_KEY', 'sk-xxxxx', 'User')

# Verify
$env:MY_CUSTOM_API_KEY

Windows (CMD):

# Set permanent environment variable
setx MY_CUSTOM_API_KEY "sk-xxxxx"

# Restart terminal, then verify
echo %MY_CUSTOM_API_KEY%

macOS/Linux (Bash):

# Add to ~/.bashrc or ~/.zshrc
echo 'export MY_CUSTOM_API_KEY="sk-xxxxx"' >> ~/.bashrc
source ~/.bashrc

# Verify
echo $MY_CUSTOM_API_KEY

⚠️ Important: You must restart your terminal after setting the environment variable!

2. Create Config File

Create a config.toml file in your project directory:

# Default model name
model = "gpt-5.1"

# Default provider name
model_provider = "tokenhub"

[model_providers.tokenhub]
name = "TokenHub"

# API base URL (replace with your TokenHub domain)
base_url = "https://hubwave.ai/v1"

# Use Responses API protocol (required)
wire_api = "responses"

# Environment variable name (not the API key itself)
env_key = "MY_CUSTOM_API_KEY"

[projects.'your-project-path']
trust_level = "trusted"

[windows]
sandbox = "elevated"

📝 Notes:

  • env_key is the environment variable name, not the API key itself
  • base_url must include the /v1 suffix
  • Replace your-project-path with your actual project path (e.g., d:\projects\myapp)

3. Start Codex

# Start in your project directory
cd your-project-path
codex

4. Test Connection

After starting, send any message to test:

› hello

If configured correctly, Codex will respond normally.

Notes

Desktop Version:

  • Simple configuration with user-friendly interface
  • All features support custom API

CLI Version:

  • Requires environment variable setup
  • Must restart terminal for changes to take effect
  • base_url must include the /v1 suffix

All models configured in your TokenHub dashboard are available.