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
- Go to the dashboard
- Sign up or log in to your account
- Navigate to API Keys → Create New Key
- Copy the key
Step 2: Install Codex CLI
npm install -g @openai/codexVerify the installation:
codex --versionStep 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-keyThen reload your shell:
source ~/.zshrc # or ~/.bashrcWindows (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 PowerShellWindows (CMD)
set OPENAI_BASE_URL=https://api.tokshub.com/v1
set OPENAI_API_KEY=sk-your-keyStep 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_URLhas 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_URLto confirm