Connect OpenAI Codex CLI to TokenCode to use any large language model for AI coding.
OpenAI Codex CLI is OpenAI's official command-line AI coding tool, which natively uses the OpenAI Chat Completions API protocol. With TokenCode, you can call Claude, Gemini, and other models in Codex.
Set the following environment variables in your terminal:
export OPENAI_API_KEY="sk-your-api-key"
export OPENAI_BASE_URL="https://tokencode.dev/v1"
Then run Codex:
codex
Edit the Codex configuration file ~/.codex/config.json:
{
"provider": "openai",
"apiKey": "sk-your-api-key",
"baseURL": "https://tokencode.dev/v1",
"model": "gpt-5.5"
}
Codex supports switching models via parameters or configuration:
# Use GPT-4o
codex --model gpt-5.5
# Use Claude Sonnet (automatic protocol conversion)
codex --model claude-sonnet-4-6
# Use Gemini 2.5 Pro (automatic protocol conversion)
codex --model gemini-2.5-pro
# Use o3 reasoning model
codex --model o3
Codex sends requests using the OpenAI protocol. When you call non-OpenAI models (such as Claude or Gemini) through TokenCode, the gateway automatically:
codex --model gpt-5.5 "Hello, verifying connection"
If you receive a normal response, the connection is configured successfully.
| Use Case | Recommended Model | Notes |
|---|---|---|
| General coding | claude-sonnet-4-6 | Excellent code understanding and generation |
| Fast completion | gpt-5.5-mini | Fast response, low cost |
| Deep reasoning | o3 | Suitable for complex logic and architecture design |
| Best value | deepseek-chat | Good performance, low price |
Make sure the URL includes the /v1 suffix: https://tokencode.dev/v1. Codex appends endpoint paths (e.g., /chat/completions) to the base URL.
Codex may validate model names. If you encounter an unrecognized model name error, try using a standard model name.
If responses are interrupted during long code generation, it may be due to max_tokens limits or rate limits. Try reducing request complexity.