TutorialsQuickstartAPI Reference

Setup guides for tools and automation workflows.

How to Use ToksHub with OpenAI Codex CLI

Point Codex CLI at one endpoint so terminal automation and product traffic share the same integration surface.

Step 1: Get Your API Key

  1. Go to the dashboard
  2. Sign up or log in to your account
  3. Navigate to API Keys Create New Key
  4. Copy the key

Step 2: Install Codex CLI

npm install -g @openai/codex

Verify the installation:

codex --version

Step 3: Configure Codex CLI

Set two environment variables to redirect Codex through ToksHub:

macOS / Linux

Add to your ~/.bashrc, ~/.zshrc, or ~/.profile:

export OPENAI_BASE_URL=https://api.tokshub.com/v1
export OPENAI_API_KEY=sk-your-key

Then reload your shell:

source ~/.zshrc  # or ~/.bashrc

Windows (PowerShell)

$env:OPENAI_BASE_URL = "https://api.tokshub.com/v1"
$env:OPENAI_API_KEY = "sk-your-key"

To make it permanent, add to your PowerShell profile ($PROFILE):

notepad $PROFILE
# Add the two lines above, save, and restart PowerShell

Windows (CMD)

set OPENAI_BASE_URL=https://api.tokshub.com/v1
set OPENAI_API_KEY=sk-your-key

Step 4: Verify the Connection

codex "Hello, can you confirm this connection is working?"

If you see a response, you're all set! Check your dashboard to see the request logged with token usage and cost.

Step 5: Start Coding

Codex CLI now routes through ToksHub. Run it in any project directory:

# Ask Codex to explain existing code
codex "Explain what this codebase does"

# Generate new functionality
codex "Add input validation to the user registration endpoint"

# Debug issues
codex "Find and fix the memory leak in this service"

Advanced: Specify a Model

ToksHub supports all OpenAI models plus other major providers. To see available model IDs:

curl https://api.tokshub.com/v1/models \
  -H "Authorization: Bearer sk-your-key"

You can also pass a model explicitly:

codex --model gpt-4.1 "Refactor this function for clarity"

Troubleshooting

  • Connection refused / timeout — Verify OPENAI_BASE_URL has no trailing slash; check status
  • Invalid API key — Use your ToksHub key, not your OpenAI key
  • Env vars not taking effect — Restart your terminal and run echo $OPENAI_BASE_URL to confirm
OpenAI Codex CLI Setup Guide — ToksHub