OpenCodex 路由
概述
本机用 OpenCodex 作为本地网关,让 Codex 桌面版同时使用 DeepSeek 和 OpenAI/Codex 官方账号,并为 DeepSeek 补齐视觉与联网搜索能力。
关键区分:模型/供应商选择 与 官方账号选择 是两件事。
- 模型/供应商 =
~/.codex/config.toml里的model与模型目录 - 官方账号 = OpenCodex 账号池里当前
selected的账号(决定 OpenAI/Codex 额度走哪个账号)
架构
Codex ──▶ OpenCodex (127.0.0.1:10100) ──▶ 本地代理 ──▶ OpenAI (chatgpt.com/backend-api/codex, 账号池)
└────────────▶ DeepSeek (api.deepseek.com, 直连/API Key)
DeepSeek 官方接口不支持图片输入。带图请求会先由“视觉旁路”模型(OpenAI)把图片描述成文字,再交给 DeepSeek 回答,因此带图请求会同时消耗 OpenAI/Codex 额度与 DeepSeek API 额度。
核心命令
- 健康检查:
ocx status或ocx health,或GET http://127.0.0.1:10100/healthz - 账号池列表:
ocx account list openai - 当前账号:
ocx account current openai - 切换账号:
ocx account use openai <account-id>,或运行scripts/switch-account.ps1 -AccountId <account-id> - 视觉旁路:
ocx agent sidecar vision --model <id> --backend openai --reasoning <low|medium|high|xhigh|max> - 联网旁路:
ocx agent sidecar web --model <id>
任务
切换模型 / 供应商
编辑 ~/.codex/config.toml 的 model(例如 deepseek-v4-pro)和 model_reasoning_effort。目标模型必须存在于 model_catalog_json 指向的目录中。openai_base_url 由 OpenCodex 自动注入,不要手改。
切换官方 Codex 账号
先 ocx account use openai <account-id>,再用 ocx account list openai 验证目标账号带 selected 标记。切换只影响之后的官方请求;正在进行的请求沿用旧账号。桌面应用右上角显示的主登录账号不会随账号池切换而改变。
配置视觉旁路
图片任务看中结果时用:
ocx agent sidecar vision --model gpt-5.6-sol --backend openai --reasoning xhigh
更看重速度、省额度时可用 gpt-5.4-mini 配合 low。--reasoning 只接受 low|medium|high|xhigh|max。
调整模型目录显示名
目录里每个模型的 slug 保持小写原文,display_name 决定界面展示。约定:去掉供应商前缀、首字母大写、删除重复条目。详见 references/config-reference.md。
资源
references/architecture.md:路由链路、端口、代理与健康检查细节references/config-reference.md:脱敏后的 config.toml / OpenCodex 配置 / 目录命名模板scripts/switch-account.ps1:脱敏、参数化的账号切换脚本scripts/build-singbox-config.ps1:从订阅重建 sing-box 配置(订阅地址已脱敏,需传入参数)