Codex CLI 配置
通过 config.toml 与 auth.json 将 Codex 接入 SimiRouter,支持 Linux、macOS 和 Windows 全平台。
Codex 当前仅支持 wire_api = "responses" 模式。手动配置只需两个文件:
- Linux / macOS:
~/.codex/config.toml与~/.codex/auth.json - Windows:
%USERPROFILE%\.codex\config.toml与%USERPROFILE%\.codex\auth.json
方式一:一键配置脚本(推荐)
我们提供了一键配置脚本,自动完成全部配置。运行前请确保已安装 Codex CLI 或 ChatGPT 桌面端,并至少运行过一次(即 ~/.codex 目录已存在)。
macOS / Linux 用户在终端中执行:
bash <(curl -fsSL https://ossga.simitalk.chat/n/idpdeuxb29fz/b/bucket-im/o/im-system/codex-simirouter-setup.sh)Windows 用户在 PowerShell 中执行:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $u = 'https://ossga.simitalk.chat/n/idpdeuxb29fz/b/bucket-im/o/im-system/codex-simirouter-setup.ps1'; $b = (New-Object Net.WebClient).DownloadData($u); if ($b.Length -ge 3 -and $b[0] -eq 0xEF -and $b[1] -eq 0xBB -and $b[2] -eq 0xBF) { $b = $b[3..($b.Length-1)] }; iex ([Text.Encoding]::UTF8.GetString($b))这条命令会下载脚本原始字节、按 UTF-8 解码后再执行,避免 Windows PowerShell 5.1 因编码差异导致中文菜单乱码。若你使用 PowerShell 7(pwsh),也可直接用 irm <脚本地址> | iex。
运行后按菜单选择要使用的模型。首次运行会提示输入 API Key(以 sk- 开头,在 SimiRouter 控制台获取)。
脚本会依次完成以下工作:
- 备份现有配置:将
~/.codex/config.toml备份到~/.codex/backup-simirouter/,随时可以还原。 - 修改
~/.codex/config.toml:只改写必要的字段(model_provider、model、推理与上下文相关参数等),并新增[model_providers.SimiRouter]配置段,指向中转base_url;你原有的 MCP 服务器、项目信任级别等配置全部保留。若存在与 SimiRouter 配置冲突的字段,脚本会删除它们,并逐条打印删除原因。 - 写入
~/.codex/auth.json:将 API Key 写入OPENAI_API_KEY,并设置600权限;即使后续被 Codex 登录流程覆盖,config.toml中的experimental_bearer_token仍会保证请求走 SimiRouter。 - 校验:写入前校验
config.toml/auth.json语法合法;校验失败则中止,不修改任何文件。
再次运行脚本可切换模型,或选择「恢复默认配置」用备份还原到安装前的状态。
方式二:Linux / macOS 手动一键配置(备用)
复制以下命令,将 替换为 API密钥 换成自己的 Key 后执行:
[ -e ~/.codex ] && mv ~/.codex ~/.codex.bk; mkdir -p ~/.codex
cat > ~/.codex/config.toml <<'EOF'
model_provider = "simirouter"
review_model = "gpt-6-astra"
model = "gpt-6-astra"
model_reasoning_effort = "xhigh"
plan_mode_reasoning_effort = "high"
model_reasoning_summary = "auto"
model_verbosity = "high"
personality = "pragmatic"
context_window = 1000000
max_context_window = 1000000
auto_compact_token_limit = 900000
model_context_window = 1000000
model_auto_compact_token_limit = 900000
approval_policy = "never"
sandbox_mode = "danger-full-access"
suppress_unstable_features_warning = true
web_search = "live"
[model_providers.simirouter]
name = "simirouter"
base_url = "https://api.dwchainless.com/v1"
wire_api = "responses"
stream_idle_timeout_ms = 900000
supports_websockets = false
http_headers = { "x-openai-actor-authorization" = "api.dwchainless.com" }
requires_openai_auth = false
experimental_bearer_token="替换为 API密钥"
[features]
goals = true
remote_connections = true
EOF
cat > ~/.codex/auth.json <<'EOF'
{
"OPENAI_API_KEY": "替换为 API密钥"
}
EOF
chmod 600 ~/.codex/auth.json即使后续 auth.json 被 Codex 登录流程覆盖,config.toml 中的 experimental_bearer_token 仍会保证模型请求走 Simi Router。
方式三:Linux / macOS 手动配置(备用)
~/.codex/config.toml
model_provider = "simirouter"
review_model = "gpt-6-astra"
model = "gpt-6-astra"
model_reasoning_effort = "xhigh"
plan_mode_reasoning_effort = "high"
model_reasoning_summary = "auto"
model_verbosity = "high"
personality = "pragmatic"
context_window = 1000000
max_context_window = 1000000
auto_compact_token_limit = 900000
model_context_window = 1000000
model_auto_compact_token_limit = 900000
approval_policy = "never"
sandbox_mode = "danger-full-access"
suppress_unstable_features_warning = true
web_search = "live"
[model_providers.simirouter]
name = "simirouter"
base_url = "https://api.dwchainless.com/v1"
wire_api = "responses"
stream_idle_timeout_ms = 900000
supports_websockets = false
http_headers = { "x-openai-actor-authorization" = "api.dwchainless.com" }
requires_openai_auth = false
experimental_bearer_token="替换为 API密钥"
[features]
goals = true
remote_connections = true~/.codex/auth.json
{
"OPENAI_API_KEY": "替换为 API密钥"
}Windows 配置
PowerShell
创建目录并打开配置文件:
New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex" | Out-Null
notepad "$env:USERPROFILE\.codex\config.toml"
notepad "$env:USERPROFILE\.codex\auth.json"CMD
if not exist "%USERPROFILE%\.codex" mkdir "%USERPROFILE%\.codex"
notepad "%USERPROFILE%\.codex\config.toml"
notepad "%USERPROFILE%\.codex\auth.json"分别将上方的 TOML 和 JSON 内容粘贴到对应文件并保存。
启动验证
codexWindows 下 config.toml 与 auth.json 路径为 %USERPROFILE%\.codex\,请确保文件保存在正确位置。
这篇文档对您有帮助吗?
最后更新于