Skip to content

Repository files navigation

Codex Live Switch / Codex 模型配置切换器

CI

Codex Live Switch 是一个面向 Codex 的轻量插件,用来安全地查看、测试、备份和更新用户级自定义模型 Provider 配置。它支持已经提供 OpenAI Responses API 兼容端点的 OpenRouter、DeepSeek 和 Ollama。

当前状态:0.3.0,实验性版本。插件能更新默认配置,但不能代替 Codex 在当前会话中执行 /model,也不承诺 Provider 变更后可以无缝热切换。

English summary: Codex Live Switch is an experimental MIT-licensed Codex plugin that safely manages user-level presets for Responses-compatible custom model providers. It validates config.toml, creates backups before writes, avoids storing raw API keys, and provides restore and connectivity checks.

为什么重新定位

早期版本把 wire_api 写成 chat_completions,并把脚本输出描述成“已尝试即时切换”。这两个说法不再符合当前 Codex:自定义 Provider 目前只支持 responses,而本项目的 Python 脚本没有调用 Codex 内部会话切换接口。

0.3.0 因此做了三个收紧:

  • 所有启用的 preset 都必须使用 wire_api = "responses"
  • 脚本只声明已经更新默认配置,并把 /model 作为用户可手动尝试的命令。
  • Provider 改变时,明确提示新建 Codex 会话来加载配置。

核心能力

  • 采用当前 Codex 插件结构:.codex-plugin/plugin.jsonskills/hooks/presets/scripts/
  • 修改 ~/.codex/config.toml 前进行 TOML 解析;解析失败时拒绝覆盖。
  • 写入候选内容后再次核对顶层模型和 Provider 字段,避免把其他 TOML 表里的同名键误当成目标。
  • 写入前备份到 ~/.codex/backups/config-YYYYMMDD-HHMMSS.toml
  • 保留无关配置和其他 Provider,只更新选中的模型与 Provider 块。
  • 只保存 API Key 的环境变量名,不把 Key 明文写入配置。
  • 提供 Provider 最小连接测试、当前状态读取和最近备份恢复。
  • SessionStart hook 只读取模型状态,不读取或打印 API Key,也不修改配置。

内置 preset

preset Provider Model 已核对的协议边界
fast OpenRouter minimax/minimax-m2.7 通过 OpenRouter /responses 使用 MiniMax M2.7
m3 OpenRouter minimax/minimax-m3 通过 OpenRouter /responses 使用 MiniMax M3
cheap DeepSeek deepseek-v4-flash DeepSeek 当前公开的 Responses API 仅支持该模型
openrouter OpenRouter openrouter/auto OpenRouter 的自动路由
local Ollama qwen2.5-coder:32b 需要 Ollama 0.13.3+;仅使用非状态式 Responses API

MiniMax 直连端点没有放进当前 preset。原因不是断言它永久不支持,而是截至本次核对,MiniMax 官方资料不足以证明其直连端点满足当前 Codex 所需的 Responses API 合约。MiniMax 模型暂时通过已公开支持 /responses 的 OpenRouter 使用。

安装

通过仓库 marketplace

codex plugin marketplace add zqj372-ops/Codex-Live-Switch --ref main
codex plugin add codex-live-switch@codex-live-switch

安装或更新插件后,请新建一个 Codex 会话,让 Codex 载入新的 skill、hook 和 Provider 配置。

仅克隆并手动运行脚本

git clone https://github.com/zqj372-ops/Codex-Live-Switch.git
cd Codex-Live-Switch
python3 scripts/list_models.py

Python 要求为 3.11+,因为脚本使用标准库 tomllib

配置 API Key

远程 Provider 从环境变量读取 Key:

export OPENROUTER_API_KEY="你的 API Key"
export DEEPSEEK_API_KEY="你的 API Key"

请不要把 Key 写入仓库、Issue、PR、日志或聊天记录。本地 Ollama preset 不需要 API Key。

在 Codex 中使用

安装后可以直接描述目标:

查看可用模型
切换到极速模式
切换到 MiniMax M3
切换到省钱模式
切换到本地模型
测试 MiniMax M3
查看当前模型配置
恢复上一次模型配置

模型切换默认调用:

python3 scripts/switch_model.py m3 --persist --print-slash-command

典型输出会区分两种状态:

  • 默认配置已更新~/.codex/config.toml 已安全写入并完成备份。
  • 当前会话未自动切换:如果当前 Provider 已加载,可手动尝试 /model <model>;如果 Provider 也改变,请新建会话。

脚本命令

python3 scripts/list_models.py
python3 scripts/switch_model.py m3 --persist --print-slash-command
python3 scripts/switch_model.py fast --dry-run
python3 scripts/test_provider.py m3
python3 scripts/status.py
python3 scripts/restore_config.py

test_provider.py 会向所选 Provider 的 /responses 端点发送一个最小请求。该操作会使用相应环境变量中的 Key 并产生真实的 Provider 请求或费用;脚本只显示脱敏后的 Key 片段。

配置写入示例

model = "minimax/minimax-m3"
model_provider = "openrouter"

[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
wire_api = "responses"
env_key = "OPENROUTER_API_KEY"

如果设置了 CODEX_HOME,配置路径为 $CODEX_HOME/config.toml;否则为 ~/.codex/config.toml

安全与限制

  • 这是配置管理插件,不是 API 代理、账号池、Key 轮询器或计费绕过工具。
  • 不保存、上传或同步 API Key。
  • 不保证第三方 Provider 实现完整的 Responses API;连接成功也不等于工具调用、流式结束事件和长会话行为全部兼容。
  • Ollama 的 Responses API 是非状态式实现,并可能因版本、模型和工具调用方式不同而存在兼容差异。
  • 任何启用的 hook 都应由用户在安装时审查和信任。
  • 本项目与 OpenAI、MiniMax、DeepSeek、OpenRouter、Ollama 均无隶属或官方背书关系。

开源维护

运行本地校验:

python3 -m unittest discover -s tests -v
python3 -m compileall -q scripts tests
python3 -m json.tool .codex-plugin/plugin.json >/dev/null
python3 -m json.tool .agents/plugins/marketplace.json >/dev/null
python3 -m json.tool hooks/hooks.json >/dev/null
python3 -m json.tool presets/models.json >/dev/null

依据

About

Safely manage, validate, back up, test, and restore Responses-compatible custom model-provider presets for Codex. Experimental; no guaranteed in-session hot switch.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages