OpenAI Codex CLI Integration
OpenAI's official command-line AI coding tool that autonomously executes coding tasks, connecting to Calgine Tokens through a custom model provider.
Codex CLI is OpenAI's official command-line AI coding agent. It completes code generation, refactoring, debugging, file editing, and system command execution through natural language in the terminal, with full sandbox isolation and fine-grained permission control.
Prerequisites
- Sign up at the Calgine Tokens Console.
- Go to Workspace → API Tokens, click "Add Token", and copy the API Key once created (starts with
sk-).
| Setting | Value |
|---|---|
base_url | https://api.calgine.com.cn/v1 |
OPENAI_API_KEY | The API token you created in the console |
Installation & Configuration
Check your Node.js version: Node.js 22+ is required:
bashnode -vInstall Codex CLI:
bashnpm install -g @openai/codexSet the API Key environment variable (choose one):
bashecho 'export OPENAI_API_KEY="sk-your-token"' >> ~/.zshrc source ~/.zshrcbashecho 'export OPENAI_API_KEY="sk-your-token"' >> ~/.bash_profile source ~/.bash_profilepowershell[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "sk-your-token", "User")Create the configuration file:
bashmkdir -p ~/.codexWrite the following into
~/.codex/config.toml:toml# ~/.codex/config.toml model = "gpt-4o" model_provider = "calgine" # Key: set the default provider disable_response_storage = true [model_providers.calgine] name = "Calgine Tokens" base_url = "https://api.calgine.com.cn/v1" env_key = "OPENAI_API_KEY" # Environment variable name (not the key itself) wire_api = "responses" # Responses API protocol (the only supported value)Three critical settings — all required:
model_provider = "calgine"— Without this, Codex routes known model names likegpt-4odirectly to OpenAIwire_api = "responses"— The only protocol Codex supports, using the Responses APIenv_key = "OPENAI_API_KEY"— This is the environment variable name, not the key value itself
Verify the Setup
codexOn first launch, you need to choose an approval mode that controls Codex's permission policy when performing actions:
| Mode | Value | Description |
|---|---|---|
| Suggested | untrusted | Default. Codex can only read files; all writes and command executions require your confirmation |
| Auto Edit | on-request | Automatically runs safe sandboxed operations; asks only when escalation is needed |
| Full Auto | never | No confirmations at all. Codex completes everything autonomously. Best for trusted environments |
Once started, enter any task (e.g., "Describe the current directory structure"). A normal result means the integration is working. You can also run /status to view the current model, token usage, and configuration.
Common Commands
| Command | Description |
|---|---|
codex | Start an interactive session |
codex "task description" | Run a one-off task directly |
codex --model gpt-4o "task" | Run a task with a specific model |
codex --image screenshot.png "fix this bug" | Attach an image as context |
/model | Switch models within a session |
/approvals | Adjust the approval policy for the current session |
/compact | Compress conversation history to free up the context window |
Recommended Models
| Scenario | Recommended Model | Notes |
|---|---|---|
| Daily coding assistance | gpt-4o | Balanced speed and capability for most tasks |
| Complex refactoring | o4-mini | Strong reasoning for deep-thinking tasks |
| Quick lightweight tasks | gpt-4o-mini | Fast responses, low cost |
Troubleshooting
401 Unauthorized — still connecting to api.openai.com
model_provider = "calgine" is not set, so Codex routes known model names (like gpt-4o) to the built-in OpenAI provider. Make sure the top level of config.toml contains model_provider = "calgine". If you previously logged into Codex with ChatGPT, also clear the cached credentials:
rm -f ~/.codex/auth.jsonenv_key configuration not working
env_key should contain the environment variable name (e.g., "OPENAI_API_KEY"), not the API Key value itself. Make sure the variable is set via export OPENAI_API_KEY="sk-...".
Note
Codex CLI's autonomous mode calls models and executes system commands frequently, consuming far more tokens than normal chat. Keep an eye on your console quota and rate limits — see Rate Limits.
Next Steps
- Gemini CLI: Google's official command-line AI tool
- Zed Editor: A high-performance editor with a built-in AI assistant
- Codex CLI Official Docs: Learn more about advanced configuration