前言

之前 开了一车英区的Team。同学都不用Codex,只有我一个人用。平时也不算重度编程,那就我一个人蹬了。

目前最好用的API整合工具应该就是CLIProxyAPI了。

CLIProxyAPI 安装与配置

下载

Releases · router-for-me/CLIProxyAPI

这里下载的都是CLI,官方的GUI在一个月前转Archived了。不过无所谓,因为CLI内已经内置了他们的网页管理面板

当然,我这里还喜欢用CPA-Manager,因为它还可以统计用量,并且估算账号限额。

下载地址在:

seakee/CPA-Manager: This is a WebUI interface based on CLI-Proxy-API, designed to simplify configuration modifications and runtime status monitoring.

同样是CLI,终端执行即可。后续需要配置管理面板,下文会讲。

配置

写一个最小的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 服务器绑定主机/接口,默认空字符串同时绑定 IPv4/IPv6。
# 使用 "127.0.0.1" 或 "localhost" 可限制仅本机访问。
host: "localhost"

# 服务器端口
port: 8317

# TLS 设置:启用后使用提供的证书与私钥监听 HTTPS。
tls:
enable: false
cert: ""
key: ""

# 管理 API 设置
remote-management:
# 是否允许远程(非 localhost)访问管理接口。
# 为 false 时仅允许 localhost,仍需管理密钥。
allow-remote: false

# 管理密钥。若填写明文,启动时会自动哈希后生效。
# 所有管理请求(包括本地)都需要该密钥。
# 留空则完全禁用管理 API(所有 /v0/management 路由返回 404)。
secret-key: "Esing233"

# 为 true 时禁用内置管理面板资源下载与路由。
disable-control-panel: false

# 管理面板的 GitHub 仓库,可填写仓库 URL 或 releases API URL。
# panel-github-repository: "https://github.com/router-for-me/Cli-Proxy-API-Management-Center"
panel-github-repository: "https://github.com/seakee/CPA-Manager"

# 认证目录(支持 ~ 展开为主目录)
auth-dir: "~/.cli-proxy-api"

# 用于请求认证的 API 密钥
api-keys:
- "sk-0d000721"

# 是否启用调试日志
debug: false

# 为 true 时禁用高开销 HTTP 中间件以降低高并发下的内存占用
commercial-mode: false

# 为 true 时将应用日志写入滚动文件而非 stdout
logging-to-file: false

# 日志目录的最大总大小(MB);超过后会删除最旧的日志。0 表示不限制。
logs-max-total-size-mb: 0

# 为 false 时禁用内存用量统计聚合
usage-statistics-enabled: true

# 代理地址。支持 socks5/http/https,例如 socks5://user:pass@192.168.1.1:1080/
proxy-url: "socks5://127.0.0.1:7890"

# 为 true 时,无前缀模型请求只会匹配无前缀凭据(除非前缀与模型名相同)。
force-model-prefix: false

# 请求重试次数;当响应码为 403/408/500/502/503/504 时重试。
request-retry: 3

# 冷却中的凭据等待的最长时间(秒),超过则触发重试。
max-retry-interval: 30

# disable-image-generation 支持:false(默认)、true、或 "chat"。
# - true:完全禁用 image_generation(同时 /v1/images/generations 与 /v1/images/edits 返回 404)。
# - "chat":仅禁用非 images 端点的 image_generation 注入,但保留 /v1/images/generations 与 /v1/images/edits 可用。
disable-image-generation: chat

# 配额超限时的处理
quota-exceeded:
switch-project: true # 配额超限时是否自动切换其他项目
switch-preview-model: true # 配额超限时是否自动切换预览模型
antigravity-credits: true # Claude credits 兜底:当所有 free-tier 凭据耗尽(429/503)时,使用带 Google One AI credits 的凭据进行最后兜底重试

# 多凭据匹配时的路由策略
routing:
strategy: "round-robin" # 轮询(默认)或 fill-first

# 为所有客户端启用会话粘性路由。
# 会话 ID 来源:metadata.user_id(Claude Code 会话格式)、
# X-Session-ID、Session_id(Codex)、X-Amp-Thread-Id(Amp CLI)、
# X-Client-Request-Id(PI)、conversation_id,或前几条消息的 hash。
# 当绑定的凭据不可用时,会自动故障转移。
session-affinity: false # 默认:false

# 会话绑定的保留时长。默认:1h
session-affinity-ttl: "1h"

# 是否为 WebSocket API (/v1/ws) 启用认证
ws-auth: false

# 当 > 0 时,为非流式响应每隔 N 秒发送空行以防止空闲超时
nonstream-keepalive-interval: 0

# 当为 true 时,为 Codex API 请求启用官方 Codex 指令注入
# 当为 false(默认)时,CodexInstructionsForModel 立即返回而不修改
codex-instructions-enabled: false

# 流式传输行为(SSE keep-alive 与安全启动重试)
streaming:
keepalive-seconds: 15 # 默认:0(禁用);≤0 关闭 keep-alive。
bootstrap-retries: 1 # 默认:0(禁用);首字节前的重试次数。

重点就几个配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 服务器绑定主机/接口,
host: "localhost"

# 服务器端口
port: 8317

# 管理 API 设置
remote-management:
# 管理密钥
secret-key: "Esing233"
# 管理面板的 GitHub 仓库,可填写仓库 URL 或 releases API URL。
# panel-github-repository: "https://github.com/router-for-me/Cli-Proxy-API-Management-Center"
panel-github-repository: "https://github.com/seakee/CPA-Manager"

# 用于请求认证的 API 密钥
api-keys:
- "sk-0d000721"

# 为 false 时禁用内存用量统计聚合
usage-statistics-enabled: true

# 代理地址
proxy-url: "socks5://127.0.0.1:7890"

不配置代理的话OAuth认证会出问题。

之后进入管理面板,在http://localhost:8317,打开中心信息 -> 外部用量统计服务,填入上面的CPA-Manager的监听端口(默认为18317),即可监测用量。


到这里,各家模型已经整合完毕了。如果使用Claude Code 这种CLI的话,已经可以结束了。

但我还想接入VSCode插件,让VSCode中的Copilot和Codex插件都用自己的本地整合API。这就要用到CC-Switch了。

CC-Switch 安装与配置

下载

Releases · farion1231/cc-switch

配置

安装好后运行,在最上面的模型切换中换到OpenAI Codex选项卡,然后新建一个配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
model_provider = "custom"
model = "gpt-5.5"
model_reasoning_effort = "xhigh"
disable_response_storage = true

[model_providers.custom]
name = "custom"
wire_api = "responses"
requires_openai_auth = true
base_url = "http://localhost:8317/v1"

[windows]
sandbox = "elevated"

要不要用xhigh看个人财力和人脉

VSCode 配置

Codex

退出登录后选择API密钥方式登录,然后填入你之前设置的sk-0d000721即可。

Copilot

VSCode Preview 专属

在右侧的Copilot Chat 选模型的地方进入设置页面,右上角添加模型可以加入OpenAI Compatible