胜算云 胜算云 文档中心 ↗ 精益社区

Codex CLI接入胜算云API

本文提供详细的配置指南,帮助你快速接入胜算云 API,统一调用多个主流 AI 模型。平台将根据请求内容自动路由到最优模型,帮你降低成本、提升响应质量。

用 CC-Switch 一键接入胜算云

  1. 下载并安装 CC-Switch

  2. 打开 CC-Switch,点击 "供应商"

  3. 在供应商列表中选择 "胜算云"

  4. 输入你的 胜算云 API Key

  5. 勾选 "写入通用配置" 以覆盖已有配置

  6. 点击启用,重启对应工具即可使用

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,无需手动编辑配置文件

GITHUB RELEASES

https://github.com/farion1231/cc-switch/releases
CC-Switch GitHub 仓库 →

- 已安装 Codex CLI(npm install -g @openai/codex) - 已获取胜算云 API Key:https://console.shengsuanyun.com/user/keys

> 在 Codex CLI 中配置胜算云作为模型提供商,无需 OpenAI 官方账号,即可使用 Claude、GPT、Gemini 等全线模型。

方式一:编辑 auth.json + config.toml(推荐)

Codex CLI 通过 auth.json 存储 API Key,通过 config.toml 配置提供商信息,两者配合使用。

1. 创建 auth.json

JSON

{
  "OPENAI_API_KEY": "你的胜算云API Key"
}

BASH

mkdir -p ~/.codex

cat > ~/.codex/auth.json << 'EOF'
{
  "OPENAI_API_KEY": "你的胜算云API Key"
}
EOF

chmod 600 ~/.codex/auth.json

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。

在 ~/.codex/ 目录下创建 auth.json,填入胜算云 API Key:

2. 创建 config.toml

TOML

model_provider = "custom"
model = "openai/gpt-5.4"
model_reasoning_effort = "high"
disable_response_storage = true

[model_providers.custom]
name = "胜算云"
base_url = "https://router.shengsuanyun.com/api/v1"
requires_openai_auth = true
wire_api = "responses"

BASH

cat > ~/.codex/config.toml << 'EOF'
model_provider = "custom"
model = "openai/gpt-5.4"
model_reasoning_effort = "high"
disable_response_storage = true

[model_providers.custom]
name = "胜算云"
base_url = "https://router.shengsuanyun.com/api/v1"
requires_openai_auth = true
wire_api = "responses"
EOF

POWERSHELL

@'
model_provider = "custom"
model = "openai/gpt-5.4"
model_reasoning_effort = "high"
disable_response_storage = true

[model_providers.custom]
name = "胜算云"
base_url = "https://router.shengsuanyun.com/api/v1"
requires_openai_auth = true
wire_api = "responses"
'@ | Set-Content -Path "$env:USERPROFILE\.codex\config.toml"
在 ~/.codex/ 目录下创建 config.toml,配置胜算云提供商:

3. 关键配置说明

字段说明
model默认使用的模型,可在胜算云模型列表中复制模型 ID
model_provider提供商标识,对应 [model_providers.xxx] 中的 xxx
base_url胜算云 API 地址,勿修改
requires_openai_auth设为 true,使 Codex 从 auth.json 的 OPENAI_API_KEY 读取密钥
wire_api协议类型,胜算云使用 "responses"

4. 切换模型

BASH

codex --model openai/gpt-5.5 "你的提示"

TOML

model_provider = "custom"
model = "openai/gpt-5.4"
model_reasoning_effort = "high"
disable_response_storage = true

[profiles.opus]
model_provider = "custom"
model = "openai/gpt-5.5"
model_reasoning_effort = "high"
disable_response_storage = true

[profiles.haiku]
model_provider = "custom"
model = "openai/gpt-5.4-mini"
model_reasoning_effort = "high"
disable_response_storage = true

[model_providers.custom]
name = "胜算云"
base_url = "https://router.shengsuanyun.com/api/v1"
requires_openai_auth = true
wire_api = "responses"
临时切换(单次会话):永久切换:修改 config.toml 中的 model 字段即可。使用 Profiles 多配置:切换:codex --profile opus "你的提示"

5. 启动验证

BASH

codex "你好,请介绍一下你自己"
如果配置正确,Codex CLI 将通过胜算云 API 返回模型响应。

方式二:使用 CC Switch 配置(最简单)

CC Switch 是一款可视化的 AI 编码工具提供商管理器,支持一键配置 Codex 的胜算云接入,无需手动编辑任何文件。

1. 下载安装 CC Switch

前往 CC Switch GitHub 下载最新版本。

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 即可使用。

常见问题

检查 auth.json 中的 Key 是否正确(无多余空格和引号)

确认胜算云账号余额充足

确认 requires_openai_auth = true,且 auth.json 中存在 OPENAI_API_KEY

BASH

codex --model
胜算云使用 wireapi = "responses" 协议,请确保 config.toml 中设置的是 wireapi = "responses" 而不是 "chat"。胜算云支持 Claude 系列、GPT 系列、Gemini 系列、千问、豆包等全线模型,详见胜算云模型列表。

相关资源

胜算云控制台:https://console.shengsuanyun.com

胜算云模型列表:https://router.shengsuanyun.com/model

胜算云 API Key 管理:https://console.shengsuanyun.com/user/keys

胜算云服务状态:https://watch.shengsuanyun.com/status/shengsuanyun

Codex CLI 官方文档:https://developers.openai.com/codex