Skip to content

Commit cebb596

Browse files
committed
feat: Add codex configuration
1 parent 3a270cc commit cebb596

File tree

26 files changed

+1893
-143
lines changed

26 files changed

+1893
-143
lines changed

CODEX_README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Codex 配置文档
2+
3+
[English](./CODEX_README_EN.md) | 中文 | [Claude文档](./README.md)
4+
(当前文档为Codex配置介绍,查看Claude Code文档请点击右上角↗️查看)
5+
6+
## 功能特性
7+
8+
- 🔄 **一键切换** - 快速在不同 Codex AI 提供商之间切换
9+
- 🔐 **自动配置** - 自动更新 auth.json 和系统环境变量
10+
- 📊 **延迟测试** - 测试所有提供商的网络延迟
11+
- 🎯 **自动优选** - 自动测试并切换到延迟最低的最优配置
12+
- 🌍 **国际化支持** - 支持中文和英文界面语言切换
13+
14+
## 快速开始
15+
16+
### 1. 配置config.toml
17+
18+
```bash
19+
# 查看当前配置路径(会显示默认路径)
20+
ccapi cx set
21+
# 或使用完整命令
22+
ccapi codex set
23+
24+
# 如果配置文件不在默认位置,可以设置自定义路径
25+
ccapi cx set <path>
26+
例如: ccapi cx set ~/.codex/config.toml
27+
28+
# 也可以在 ~/.ccapi-config.json 中配置 Codex config路径
29+
```json5
30+
{
31+
"codexConfigPath": "~/.codex/config.toml"
32+
}
33+
```
34+
35+
**Codex官方默认配置config.toml路径:**
36+
37+
- macOS/Linux: `~/.codex/config.toml`
38+
- Windows: `%USERPROFILE%\.codex\config.toml`
39+
40+
**注意:使用切换命令前需要在config.toml文件中配置 api_key 和 models (这两个属性非官方属性,仅ccapi使用):**
41+
42+
- api_key: 切换环境变量使用
43+
- 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+
--需添加下面两项才可正常切换配置--
54+
api_key = "your-api-key"
55+
models = [
56+
"gpt-5-codex",
57+
"gpt-5"
58+
]
59+
```
60+
61+
### 2. 查看可用提供商
62+
63+
```bash
64+
ccapi cx ls 或 ccapi codex ls
65+
```
66+
67+
### 3. 切换提供商
68+
69+
切换到指定的 Codex 提供商,可选择性地同时切换模型。
70+
71+
```bash
72+
# 基本切换
73+
ccapi cx use <提供商名称>
74+
75+
# 同时切换模型(使用第2个模型,模型索引从1开始)
76+
ccapi cx use <提供商名称> -m <模型索引>
77+
78+
# 切换到 any 提供商,使用默认模型(第1个)
79+
ccapi cx use any
80+
81+
# 切换到 any 提供商,使用第2个模型
82+
ccapi cx use any -m 2
83+
84+
# 1. 修改配置文件的 `model_provider` 字段为指定的提供商名称
85+
# 2. 如果指定了 `-m`,同时修改 `model` 字段为对应的模型
86+
# 3. 更新 `~/.codex/auth.json` 文件的 `OPENAI_API_KEY` 字段
87+
# 4. 设置系统环境变量(使用提供商的 `env_key` 作为键名)
88+
```
89+
90+
### 4. 测试提供商的URL延迟
91+
92+
```bash
93+
ccapi cx ping
94+
```
95+
96+
### 5. 测试提供商的API是否在Codex Cli中可用
97+
98+
```bash
99+
ccapi cx test
100+
```
101+
102+
### 6. 自动查找最优路线并切换配置
103+
104+
```bash
105+
# 会先进行所有配置测试,然后选择最优的配置进行自动切换,默认以test命令测试的结果为基准切换
106+
ccapi cx auto
107+
108+
# 以ping结果为准进行切换
109+
ccapi cx auto -p
110+
111+
# 以test结果为准进行切换(默认)
112+
ccapi cx auto -t
113+
```
114+
115+
## 常见问题
116+
117+
### Q1: 配置文件不存在怎么办?
118+
119+
**A:** ccapi 会自动检测默认路径。如果配置文件不存在,会提示错误并显示默认路径。你需要:
120+
121+
1. 确保 Codex 已安装并初始化
122+
2. 或者手动创建配置文件
123+
3. 使用 `ccapi -cx set` 指定自定义路径
124+
125+
### Q2: 切换后为什么不生效?
126+
127+
**A:** 环境变量需要重启终端才能生效。请:
128+
129+
1. 关闭当前终端
130+
2. 打开新终端
131+
3. 验证环境变量:`echo xxx`(替换为你的 env_key)
132+
133+
### Q3: 如何管理多个提供商?
134+
135+
**A:** 在配置文件的 `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+
然后使用 `ccapi -cx use provider1``ccapi -cx use provider2` 切换。

CODEX_README_EN.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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

Comments
 (0)