Codex CLI接入胜算云API
https://router.shengsuanyun.com/api/v1Bearer YOUR_API_KEY用 CC-Switch 一键接入胜算云
下载并安装 CC-Switch
打开 CC-Switch,点击 "供应商"
在供应商列表中选择 "胜算云"
输入你的 胜算云 API Key
勾选 "写入通用配置" 以覆盖已有配置
点击启用,重启对应工具即可使用
Codex CLI 使用 CC-Switch 注意事项
API 地址格式选择 OpenAI 兼容
Base URL 为 https://router.shengsuanyun.com/api/v1(注意:有 /v1 后缀)
目前仅支持 GPT 系列和部分 Qwen 模型(通过 /v1/responses 端点)
⚠️ 绝对不要在 Codex 里手动切换模型! 一切通过 CC-Switch 操作 + 重启 Codex
模型配置保持为 shengsuanyun-自定义-高
必须勾选 "写入通用配置"
下载安装
macOS:支持 brew install 或直接下载 .dmg 安装包
Windows:下载 .msi 安装包,双击安装
Linux:提供 .deb 和 .rpm 安装包
支持 Claude Code、Codex、OpenCode、OpenClaw、Hermes Agent 等多工具一键配置
自动管理 API Key 和 Base URL,无需手动编辑配置文件
https://github.com/farion1231/cc-switch/releases CC-Switch GitHub 仓库 →
> 在 Codex CLI 中配置胜算云作为模型提供商,无需 OpenAI 官方账号,即可使用 Claude、GPT、Gemini 等全线模型。
- 已安装 Codex CLI(npm install -g @openai/codex)
- 已获取胜算云 API Key:https://console.shengsuanyun.com/user/keys
方式一:编辑 auth.json + config.toml(推荐)
Codex CLI 通过 auth.json 存储 API Key,通过 config.toml 配置提供商信息,两者配合使用。
1. 创建 auth.json
在 ~/.codex/ 目录下创建 auth.json,填入胜算云 API Key:
{
"OPENAI_API_KEY": "你的胜算云API Key"
}|
Mac / Linux
BASH 复制mkdir -p ~/.codex
cat > ~/.codex/auth.json << 'EOF'
{
"OPENAI_API_KEY": "你的胜算云API Key"
}
EOF
chmod 600 ~/.codex/auth.json |
Windows PowerShell
POWERSHELL 复制New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.codex"
@'
{
"OPENAI_API_KEY": "你的胜算云API Key"
}
'@ | Set-Content -Path "$env:USERPROFILE\.codex\auth.json" |
auth.json 包含明文密钥,切勿提交到 Git 仓库或分享给他人。建议在 .gitignore 中添加 auth.json。
2. 创建 config.toml
在 ~/.codex/ 目录下创建 config.toml,配置胜算云提供商:
model = "openai/gpt-5.4" model_provider = "shengsuanyun" [model_providers.shengsuanyun] name = "胜算云" base_url = "https://router.shengsuanyun.com/api/v1" env_key = "OPENAI_API_KEY" wire_api = "responses"
|
Mac / Linux
BASH 复制cat > ~/.codex/config.toml << 'EOF' model = "openai/gpt-5.4" model_provider = "shengsuanyun" [model_providers.shengsuanyun] name = "胜算云" base_url = "https://router.shengsuanyun.com/api/v1" env_key = "OPENAI_API_KEY" wire_api = "responses" EOF |
Windows PowerShell
POWERSHELL 复制@' model = "openai/gpt-5.4" model_provider = "shengsuanyun" [model_providers.shengsuanyun] name = "胜算云" base_url = "https://router.shengsuanyun.com/api/v1" env_key = "OPENAI_API_KEY" wire_api = "responses" '@ | Set-Content -Path "$env:USERPROFILE\.codex\config.toml" |
3. 关键配置说明
| 字段 | 说明 |
|---|---|
model | 默认使用的模型,可在胜算云模型列表中复制模型 ID |
model_provider | 提供商标识,对应 [model_providers.xxx] 中的 xxx |
base_url | 胜算云 API 地址,勿修改 |
env_key | 从 auth.json 中读取的 Key 字段名,保持 OPENAIAPIKEY 即可 |
wire_api | 协议类型,胜算云使用 "responses" |
4. 切换模型
临时切换(单次会话):
codex --model openai/gpt-5.5 "你的提示"
永久切换:修改 config.toml 中的 model 字段即可。
使用 Profiles 多配置:
model = "openai/gpt-5.4" model_provider = "shengsuanyun" [profiles.opus] model = "openai/gpt-5.5" model_provider = "shengsuanyun" [profiles.haiku] model = "openai/gpt-5.4-mini" model_provider = "shengsuanyun" [model_providers.shengsuanyun] name = "胜算云" base_url = "https://router.shengsuanyun.com/api/v1" env_key = "OPENAI_API_KEY" wire_api = "responses"
切换:codex --profile opus "你的提示"
5. 启动验证
codex "你好,请介绍一下你自己"
如果配置正确,Codex CLI 将通过胜算云 API 返回模型响应。
方式二:使用 CC Switch 配置(最简单)
CC Switch 是一款可视化的 AI 编码工具提供商管理器,支持一键配置 Codex 的胜算云接入,无需手动编辑任何文件。
2. 选择 Codex 工具
打开 CC Switch,在左侧工具列表中选择 Codex。
3. 添加胜算云供应商
点击右上角 + 按钮,在预设供应商列表中选择 「胜算云」。
4. 填写 API Key
前往胜算云控制台 https://console.shengsuanyun.com/user/keys 创建并复制 API Key,粘贴到 CC Switch 的 API Key 输入框中。
5. 获取模型列表
点击 「获取模型列表」 按钮,CC Switch 会自动拉取胜算云支持的模型清单。
6. 选择模型
从模型列表中选择你想使用的模型(如 openai/gpt-5.4)。
7. 写入配置
勾选 「写入通用配置到 config.toml」,CC Switch 会自动将配置写入 ~/.codex/config.toml 和 auth.json。
如果你的模型支持 1M 上下文窗口,可额外勾选 「1M 上下文窗口」 选项以启用超长上下文能力。
8. 完成配置
点击确认,CC Switch 自动完成所有配置文件的修改。打开 Codex CLI 即可使用。
常见问题
Support for the "chat" wire API is deprecated 怎么办?胜算云使用 wireapi = "responses" 协议,请确保 config.toml 中设置的是 wireapi = "responses" 而不是 "chat"。
检查 auth.json 中的 Key 是否正确(无多余空格和引号)
确认胜算云账号余额充足
确认 env_key 的值与 auth.json 中的 Key 字段名一致
codex --model
胜算云支持 Claude 系列、GPT 系列、Gemini 系列、千问、豆包等全线模型,详见胜算云模型列表。
相关资源
胜算云 API Key 管理:https://console.shengsuanyun.com/user/keys
Codex CLI 官方文档:https://developers.openai.com/codex