|
| 1 | +# Codex Configuration Guide |
| 2 | + |
| 3 | +English | [中文](./CODEX_README.md) | [Claude Documentation](./README_EN.md) |
| 4 | +(Current document is for Codex configuration. For Claude Code documentation, click the link above ↗️) |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +- 🔄 **One-Click Switching** - Quickly switch between different Codex AI providers |
| 9 | +- 🔐 **Auto Configuration** - Automatically updates auth.json and system environment variables |
| 10 | +- 📊 **Latency Testing** - Test network latency for all providers |
| 11 | +- 🎯 **Auto Optimization** - Automatically test and switch to optimal configuration with lowest latency |
| 12 | +- 🌍 **Internationalization** - Supports Chinese and English interface language switching |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +### 1. Configure config.toml |
| 17 | + |
| 18 | +```bash |
| 19 | +# View current config path (shows default path) |
| 20 | +ccapi cx set |
| 21 | +# Or use full command |
| 22 | +ccapi codex set |
| 23 | + |
| 24 | +# If config file is not in default location, set custom path |
| 25 | +ccapi cx set <path> |
| 26 | +Example: ccapi cx set ~/.codex/config.toml |
| 27 | + |
| 28 | +# Can also configure Codex config path in ~/.ccapi-config.json |
| 29 | +```json5 |
| 30 | +{ |
| 31 | + "codexConfigPath": "~/.codex/config.toml" |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +**Official Codex default config.toml paths:** |
| 36 | + |
| 37 | +- macOS/Linux: `~/.codex/config.toml` |
| 38 | +- Windows: `%USERPROFILE%\.codex\config.toml` |
| 39 | + |
| 40 | +**Note: Before using switch command, you need to configure api_key and models in config.toml file (these are non-official properties, used by ccapi only):** |
| 41 | + |
| 42 | +- api_key: Used for switching environment variables |
| 43 | +- models: Array format, used for switching different models |
| 44 | + |
| 45 | +```toml |
| 46 | +[model_providers.any] |
| 47 | +name = "any" |
| 48 | +base_url = "https://anyrouter.top/v1" |
| 49 | +env_key = "any" |
| 50 | +wire_api = "responses" |
| 51 | +requires_openai_auth = true |
| 52 | +
|
| 53 | +--Add the following two items to enable normal configuration switching-- |
| 54 | +api_key = "your-api-key" |
| 55 | +models = [ |
| 56 | + "gpt-5-codex", |
| 57 | + "gpt-5" |
| 58 | +] |
| 59 | +``` |
| 60 | + |
| 61 | +### 2. View Available Providers |
| 62 | + |
| 63 | +```bash |
| 64 | +ccapi cx ls or ccapi codex ls |
| 65 | +``` |
| 66 | + |
| 67 | +### 3. Switch Provider |
| 68 | + |
| 69 | +Switch to specified Codex provider, optionally switch model simultaneously. |
| 70 | + |
| 71 | +```bash |
| 72 | +# Basic switch |
| 73 | +ccapi cx use <provider-name> |
| 74 | +
|
| 75 | +# Switch with model (use 2nd model, model index starts from 1) |
| 76 | +ccapi cx use <provider-name> -m <model-index> |
| 77 | +
|
| 78 | +# Switch to any provider, use default model (1st) |
| 79 | +ccapi cx use any |
| 80 | +
|
| 81 | +# Switch to any provider, use 2nd model |
| 82 | +ccapi cx use any -m 2 |
| 83 | +
|
| 84 | +# 1. Modifies config file's `model_provider` field to specified provider name |
| 85 | +# 2. If `-m` is specified, also modifies `model` field to corresponding model |
| 86 | +# 3. Updates `~/.codex/auth.json` file's `OPENAI_API_KEY` field |
| 87 | +# 4. Sets system environment variable (uses provider's `env_key` as key name) |
| 88 | +``` |
| 89 | + |
| 90 | +### 4. Test Provider URL Latency |
| 91 | + |
| 92 | +```bash |
| 93 | +ccapi cx ping |
| 94 | +``` |
| 95 | + |
| 96 | +### 5. Test if Provider API Works in Codex CLI |
| 97 | + |
| 98 | +```bash |
| 99 | +ccapi cx test |
| 100 | +``` |
| 101 | + |
| 102 | +### 6. Auto Select Optimal Configuration |
| 103 | + |
| 104 | +```bash |
| 105 | +# Will first test all configurations, then select the optimal configuration for automatic switching, defaults to test command results as benchmark for switching |
| 106 | +ccapi cx auto |
| 107 | +
|
| 108 | +# Use ping results as benchmark for switching |
| 109 | +ccapi cx auto -p |
| 110 | +
|
| 111 | +# Use test results as benchmark for switching (default) |
| 112 | +ccapi cx auto -t |
| 113 | +``` |
| 114 | + |
| 115 | +## FAQ |
| 116 | + |
| 117 | +### Q1: What if config file doesn't exist? |
| 118 | + |
| 119 | +**A:** ccapi will auto-detect default path. If config file doesn't exist, it shows an error with default path. You need to: |
| 120 | +
|
| 121 | +1. Ensure Codex is installed and initialized |
| 122 | +2. Or manually create config file |
| 123 | +3. Use `ccapi cx set` to specify custom path |
| 124 | +
|
| 125 | +### Q2: Why doesn't it take effect after switching? |
| 126 | + |
| 127 | +**A:** Environment variables require terminal restart. Please: |
| 128 | + |
| 129 | +1. Close current terminal |
| 130 | +2. Open new terminal |
| 131 | +3. Verify environment variable: `echo xxx` (replace with your env_key) |
| 132 | + |
| 133 | +### Q3: How to manage multiple providers? |
| 134 | + |
| 135 | +**A:** Add multiple providers in config file's `model_providers`: |
| 136 | +
|
| 137 | +```toml |
| 138 | +[model_providers.provider1] |
| 139 | +name = "Provider 1" |
| 140 | +base_url = "https://api.provider1.com/v1" |
| 141 | +env_key = "provider1" |
| 142 | +api_key = "key1" |
| 143 | +models = ["model1", "model2"] |
| 144 | +
|
| 145 | +[model_providers.provider2] |
| 146 | +name = "Provider 2" |
| 147 | +base_url = "https://api.provider2.com/v1" |
| 148 | +env_key = "provider2" |
| 149 | +api_key = "key2" |
| 150 | +models = ["model3", "model4"] |
| 151 | +``` |
| 152 | +
|
| 153 | +Then use `ccapi cx use provider1` or `ccapi cx use provider2` to switch. |
0 commit comments