Spaces:
Paused
Paused
icebear0828 Claude Opus 4.6 commited on
Commit ·
1dcf4e8
1
Parent(s): b7d4394
docs: clarify proxy_api_key config, set default to "pwd"
Browse files- README.md +66 -31
- config/default.yaml +1 -1
README.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
<img src="https://img.shields.io/badge/Runtime-Node.js_18+-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js">
|
| 9 |
<img src="https://img.shields.io/badge/Language-TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript">
|
| 10 |
<img src="https://img.shields.io/badge/Framework-Hono-E36002?style=flat-square" alt="Hono">
|
|
|
|
| 11 |
<img src="https://img.shields.io/badge/License-Non--Commercial-red?style=flat-square" alt="License">
|
| 12 |
</p>
|
| 13 |
|
|
@@ -15,6 +16,7 @@
|
|
| 15 |
<a href="#-快速开始-quick-start">快速开始</a> •
|
| 16 |
<a href="#-核心功能-features">核心功能</a> •
|
| 17 |
<a href="#-技术架构-architecture">技术架构</a> •
|
|
|
|
| 18 |
<a href="#-客户端接入-client-setup">客户端接入</a> •
|
| 19 |
<a href="#-配置说明-configuration">配置说明</a>
|
| 20 |
</p>
|
|
@@ -60,28 +62,33 @@ curl http://localhost:8080/v1/chat/completions \
|
|
| 60 |
|
| 61 |
## 🌟 核心功能 (Features)
|
| 62 |
|
| 63 |
-
### 1. 🔌 全协议兼容 (
|
| 64 |
-
- 完全兼容 `/v1/chat/completions`
|
| 65 |
- 支持 SSE 流式输出,可直接对接所有 OpenAI SDK 和客户端
|
| 66 |
- 自动完成 Chat Completions ↔ Codex Responses API 双向协议转换
|
| 67 |
|
| 68 |
### 2. 🔐 账号管理与智能轮换 (Auth & Multi-Account)
|
| 69 |
- **OAuth PKCE 登录** — 浏览器一键授权,无需手动复制 Token
|
| 70 |
- **多账号轮换** — 支持 `least_used`(最少使用优先)和 `round_robin`(轮询)两种调度策略
|
| 71 |
-
- **Token 自动续期** — JWT 到期前自动刷新,
|
| 72 |
-
- **配额实时监控** — 控制面板展示各账号剩余用量
|
|
|
|
| 73 |
|
| 74 |
### 3. 🛡️ 反检测与协议伪装 (Anti-Detection)
|
| 75 |
-
- **Chrome TLS 指纹** — 通过 curl-impersonate 模拟 Chrome
|
| 76 |
-
- **
|
|
|
|
| 77 |
- **桌面上下文注入** — 每个请求自动注入 Codex Desktop 的系统提示词,实现完整的功能对等
|
| 78 |
-
- **Cookie 持久化** —
|
| 79 |
- **时间抖动 (Jitter)** — 定时操作加入随机偏移,消除机械化行为特征
|
| 80 |
|
| 81 |
-
### 4. 🔄
|
| 82 |
-
- **多轮对话关联** — 自动维护 `previous_response_id`,保持上下文连贯
|
| 83 |
- **Appcast 版本追踪** — 定时轮询 Codex Desktop 更新源,自动同步 `app_version` 与 `build_number`
|
| 84 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
## 🏗️ 技术架构 (Architecture)
|
| 87 |
|
|
@@ -92,6 +99,7 @@ curl http://localhost:8080/v1/chat/completions \
|
|
| 92 |
│ Client (Cursor / Continue / SDK) │
|
| 93 |
│ │ │
|
| 94 |
│ POST /v1/chat/completions │
|
|
|
|
| 95 |
│ │ │
|
| 96 |
│ ▼ │
|
| 97 |
│ ┌──────────┐ ┌───────────────┐ ┌──────────┐ │
|
|
@@ -109,6 +117,10 @@ curl http://localhost:8080/v1/chat/completions \
|
|
| 109 |
│ │ OAuth/JWT│ │ Headers/UA │ │ Manager │ │
|
| 110 |
│ └──────────┘ └──────���────────┘ └─────────────┘ │
|
| 111 |
│ │
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
└─────────────────────────────────────────────────────┘
|
| 113 |
│
|
| 114 |
curl subprocess
|
|
@@ -123,7 +135,10 @@ curl http://localhost:8080/v1/chat/completions \
|
|
| 123 |
|
| 124 |
| 模型 ID | 别名 | 说明 |
|
| 125 |
|---------|------|------|
|
| 126 |
-
| `gpt-5.
|
|
|
|
|
|
|
|
|
|
| 127 |
| `gpt-5.1-codex-mini` | `codex-mini` | 轻量快速编程模型 |
|
| 128 |
|
| 129 |
> 模型列表会随 Codex Desktop 版本更新自动同步。
|
|
@@ -139,7 +154,7 @@ http://localhost:8080/v1
|
|
| 139 |
|
| 140 |
API Key(从控制面板获取):
|
| 141 |
```
|
| 142 |
-
|
| 143 |
```
|
| 144 |
|
| 145 |
### Continue (VS Code)
|
|
@@ -152,7 +167,7 @@ codex-proxy-xxxxx
|
|
| 152 |
"provider": "openai",
|
| 153 |
"model": "codex",
|
| 154 |
"apiBase": "http://localhost:8080/v1",
|
| 155 |
-
"apiKey": "
|
| 156 |
}]
|
| 157 |
}
|
| 158 |
```
|
|
@@ -164,7 +179,7 @@ from openai import OpenAI
|
|
| 164 |
|
| 165 |
client = OpenAI(
|
| 166 |
base_url="http://localhost:8080/v1",
|
| 167 |
-
api_key="
|
| 168 |
)
|
| 169 |
|
| 170 |
response = client.chat.completions.create(
|
|
@@ -184,7 +199,7 @@ import OpenAI from "openai";
|
|
| 184 |
|
| 185 |
const client = new OpenAI({
|
| 186 |
baseURL: "http://localhost:8080/v1",
|
| 187 |
-
apiKey: "
|
| 188 |
});
|
| 189 |
|
| 190 |
const stream = await client.chat.completions.create({
|
|
@@ -209,18 +224,18 @@ docker compose up -d
|
|
| 209 |
# 打开 http://localhost:8080 登录
|
| 210 |
```
|
| 211 |
|
|
|
|
|
|
|
| 212 |
### 原生部署(macOS / Linux)
|
| 213 |
|
| 214 |
```bash
|
| 215 |
git clone https://github.com/icebear0828/codex-proxy.git
|
| 216 |
cd codex-proxy
|
| 217 |
-
npm install
|
| 218 |
-
npm run build
|
| 219 |
-
npm start
|
| 220 |
# 打开 http://localhost:8080 登录
|
| 221 |
```
|
| 222 |
|
| 223 |
-
> Docker 部署
|
| 224 |
|
| 225 |
## ⚙️ 配置说明 (Configuration)
|
| 226 |
|
|
@@ -228,29 +243,46 @@ npm start
|
|
| 228 |
|
| 229 |
| 分类 | 关键配置 | 说明 |
|
| 230 |
|------|---------|------|
|
| 231 |
-
| `server` | `host`, `port`, `proxy_api_key` | 服务监听地址与 API 密钥 |
|
| 232 |
| `api` | `base_url`, `timeout_seconds` | 上游 API 地址与请求超时 |
|
| 233 |
-
| `
|
| 234 |
| `model` | `default`, `default_reasoning_effort` | 默认模型与推理强度 |
|
| 235 |
| `auth` | `rotation_strategy`, `rate_limit_backoff_seconds` | 轮换策略与限流退避 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
### 环境变量覆盖
|
| 238 |
|
| 239 |
| 环境变量 | 覆盖配置 |
|
| 240 |
|---------|---------|
|
| 241 |
| `PORT` | `server.port` |
|
| 242 |
-
| `CODEX_PLATFORM` | `
|
| 243 |
-
| `CODEX_ARCH` | `
|
|
|
|
| 244 |
|
| 245 |
## 📡 API 端点一览 (API Endpoints)
|
| 246 |
|
| 247 |
| 端点 | 方法 | 说明 |
|
| 248 |
|------|------|------|
|
| 249 |
-
| `/v1/chat/completions` | POST | 聊天补全(核心端点) |
|
|
|
|
| 250 |
| `/v1/models` | GET | 可用模型列表 |
|
| 251 |
| `/health` | GET | 健康检查 |
|
| 252 |
-
| `/auth/accounts` | GET | 账号列表
|
| 253 |
-
| `/auth/login` | GET | OAuth 登录入口 |
|
| 254 |
| `/debug/fingerprint` | GET | 调试:查看当前伪装头信息 |
|
| 255 |
|
| 256 |
## 🔧 命令 (Commands)
|
|
@@ -260,18 +292,21 @@ npm start
|
|
| 260 |
| `npm run dev` | 开发模式启动(热重载) |
|
| 261 |
| `npm run build` | 编译 TypeScript 到 `dist/` |
|
| 262 |
| `npm start` | 运行编译后的生产版本 |
|
|
|
|
| 263 |
|
| 264 |
## 📋 系统要求 (Requirements)
|
| 265 |
|
| 266 |
-
- **Node.js** 18+
|
| 267 |
-
- **curl** — 系统自带即可;
|
| 268 |
-
- **ChatGPT 账号** — 普通账号即可
|
|
|
|
| 269 |
|
| 270 |
## ⚠️ 注意事项 (Notes)
|
| 271 |
|
| 272 |
- Codex API 为**流式输出专用**,设置 `stream: false` 时代理会内部流式收集后返回完整 JSON
|
| 273 |
-
- 本项目依赖 Codex Desktop 的公开接口,上游版本更新
|
| 274 |
-
- 建议在 **Linux / macOS** 上部署以获得完整 TLS 伪装能力(Windows 下 curl-impersonate 暂不可用)
|
|
|
|
| 275 |
|
| 276 |
## 📄 许可协议 (License)
|
| 277 |
|
|
|
|
| 8 |
<img src="https://img.shields.io/badge/Runtime-Node.js_18+-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js">
|
| 9 |
<img src="https://img.shields.io/badge/Language-TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript">
|
| 10 |
<img src="https://img.shields.io/badge/Framework-Hono-E36002?style=flat-square" alt="Hono">
|
| 11 |
+
<img src="https://img.shields.io/badge/Docker-Supported-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker">
|
| 12 |
<img src="https://img.shields.io/badge/License-Non--Commercial-red?style=flat-square" alt="License">
|
| 13 |
</p>
|
| 14 |
|
|
|
|
| 16 |
<a href="#-快速开始-quick-start">快速开始</a> •
|
| 17 |
<a href="#-核心功能-features">核心功能</a> •
|
| 18 |
<a href="#-技术架构-architecture">技术架构</a> •
|
| 19 |
+
<a href="#-部署方式-deployment">部署方式</a> •
|
| 20 |
<a href="#-客户端接入-client-setup">客户端接入</a> •
|
| 21 |
<a href="#-配置说明-configuration">配置说明</a>
|
| 22 |
</p>
|
|
|
|
| 62 |
|
| 63 |
## 🌟 核心功能 (Features)
|
| 64 |
|
| 65 |
+
### 1. 🔌 全协议兼容 (Multi-Protocol API)
|
| 66 |
+
- 完全兼容 `/v1/chat/completions`(OpenAI)、`/v1/messages`(Anthropic)和 Gemini 格式
|
| 67 |
- 支持 SSE 流式输出,可直接对接所有 OpenAI SDK 和客户端
|
| 68 |
- 自动完成 Chat Completions ↔ Codex Responses API 双向协议转换
|
| 69 |
|
| 70 |
### 2. 🔐 账号管理与智能轮换 (Auth & Multi-Account)
|
| 71 |
- **OAuth PKCE 登录** — 浏览器一键授权,无需手动复制 Token
|
| 72 |
- **多账号轮换** — 支持 `least_used`(最少使用优先)和 `round_robin`(轮询)两种调度策略
|
| 73 |
+
- **Token 自动续期** — JWT 到期前自动刷新,指数退避重试(5 次),临时失败 10 分钟恢复调度
|
| 74 |
+
- **配额实时监控** — 控制面板展示各账号剩余用量,限流窗口滚动时自动重置计数器
|
| 75 |
+
- **关键数据即时持久化** — 新增/刷新 Token 立即写盘,不丢失
|
| 76 |
|
| 77 |
### 3. 🛡️ 反检测与协议伪装 (Anti-Detection)
|
| 78 |
+
- **Chrome TLS 指纹** — 通过 curl-impersonate 模拟 Chrome 完整 TLS 握手特征
|
| 79 |
+
- **TLS 版本对齐** — `sec-ch-ua` 的 Chromium 版本与 TLS profile 动态同步(如 Chrome 136)
|
| 80 |
+
- **完整 HTTP 指纹** — 所有请求(包括 OAuth、appcast)统一注入 User-Agent、sec-ch-ua、sec-fetch-* 等桌面端请求头
|
| 81 |
- **桌面上下文注入** — 每个请求自动注入 Codex Desktop 的系统提示词,实现完整的功能对等
|
| 82 |
+
- **Cookie 持久化** — v2 格式保留过期时间,关键 Cookie(cf_clearance)变更时即时写盘
|
| 83 |
- **时间抖动 (Jitter)** — 定时操作加入随机偏移,消除机械化行为特征
|
| 84 |
|
| 85 |
+
### 4. 🔄 自动维护与版本追踪 (Auto-Maintenance)
|
|
|
|
| 86 |
- **Appcast 版本追踪** — 定时轮询 Codex Desktop 更新源,自动同步 `app_version` 与 `build_number`
|
| 87 |
+
- **全自动指纹更新** — 检测到新版本后自动触发完整流水线:下载 → 解压 → 提取指纹 → 热更新配置
|
| 88 |
+
- **Chromium 版本提取** — 从 Codex Desktop 安装包自动提取 Electron/Chromium 版本,同步 TLS profile
|
| 89 |
+
- **配置热重载** — full-update 完成后自动重载 config + fingerprint,无需重启
|
| 90 |
+
- **多轮对话关联** — 自动维护 `previous_response_id`,保持上下文连贯
|
| 91 |
+
- **Web 控制面板** — 账号管理、用量监控、状态总览,中英双语
|
| 92 |
|
| 93 |
## 🏗️ 技术架构 (Architecture)
|
| 94 |
|
|
|
|
| 99 |
│ Client (Cursor / Continue / SDK) │
|
| 100 |
│ │ │
|
| 101 |
│ POST /v1/chat/completions │
|
| 102 |
+
│ POST /v1/messages (Anthropic) │
|
| 103 |
│ │ │
|
| 104 |
│ ▼ │
|
| 105 |
│ ┌──────────┐ ┌───────────────┐ ┌──────────┐ │
|
|
|
|
| 117 |
│ │ OAuth/JWT│ │ Headers/UA │ │ Manager │ │
|
| 118 |
│ └──────────┘ └──────���────────┘ └─────────────┘ │
|
| 119 |
│ │
|
| 120 |
+
│ ┌──────────────────────────────────────────────┐ │
|
| 121 |
+
│ │ Auto-Maintenance (update-checker + scripts) │ │
|
| 122 |
+
│ └──────────────────────────────────────────────┘ │
|
| 123 |
+
│ │
|
| 124 |
└─────────────────────────────────────────────────────┘
|
| 125 |
│
|
| 126 |
curl subprocess
|
|
|
|
| 135 |
|
| 136 |
| 模型 ID | 别名 | 说明 |
|
| 137 |
|---------|------|------|
|
| 138 |
+
| `gpt-5.3-codex` | `codex` | 最新旗舰 agentic 编程模型(默认) |
|
| 139 |
+
| `gpt-5.2-codex` | — | 上一代 agentic 编程模型 |
|
| 140 |
+
| `gpt-5.1-codex-max` | `codex-max` | 深度推理编程模型 |
|
| 141 |
+
| `gpt-5.2` | — | 通用旗舰模型 |
|
| 142 |
| `gpt-5.1-codex-mini` | `codex-mini` | 轻量快速编程模型 |
|
| 143 |
|
| 144 |
> 模型列表会随 Codex Desktop 版本更新自动同步。
|
|
|
|
| 154 |
|
| 155 |
API Key(从控制面板获取):
|
| 156 |
```
|
| 157 |
+
your-api-key
|
| 158 |
```
|
| 159 |
|
| 160 |
### Continue (VS Code)
|
|
|
|
| 167 |
"provider": "openai",
|
| 168 |
"model": "codex",
|
| 169 |
"apiBase": "http://localhost:8080/v1",
|
| 170 |
+
"apiKey": "your-api-key"
|
| 171 |
}]
|
| 172 |
}
|
| 173 |
```
|
|
|
|
| 179 |
|
| 180 |
client = OpenAI(
|
| 181 |
base_url="http://localhost:8080/v1",
|
| 182 |
+
api_key="your-api-key"
|
| 183 |
)
|
| 184 |
|
| 185 |
response = client.chat.completions.create(
|
|
|
|
| 199 |
|
| 200 |
const client = new OpenAI({
|
| 201 |
baseURL: "http://localhost:8080/v1",
|
| 202 |
+
apiKey: "your-api-key",
|
| 203 |
});
|
| 204 |
|
| 205 |
const stream = await client.chat.completions.create({
|
|
|
|
| 224 |
# 打开 http://localhost:8080 登录
|
| 225 |
```
|
| 226 |
|
| 227 |
+
数据持久化通过 volume 映射:`data/`(账号、Cookie)和 `config/`(配置文件)。
|
| 228 |
+
|
| 229 |
### 原生部署(macOS / Linux)
|
| 230 |
|
| 231 |
```bash
|
| 232 |
git clone https://github.com/icebear0828/codex-proxy.git
|
| 233 |
cd codex-proxy
|
| 234 |
+
npm install && npm run build && npm start
|
|
|
|
|
|
|
| 235 |
# 打开 http://localhost:8080 登录
|
| 236 |
```
|
| 237 |
|
| 238 |
+
> Docker 部署自动安装 curl-impersonate(Linux 版)和 unzip(自动更新用)。原生部署依赖 `npm install` 的 postinstall 脚本自动下载 curl-impersonate。
|
| 239 |
|
| 240 |
## ⚙️ 配置说明 (Configuration)
|
| 241 |
|
|
|
|
| 243 |
|
| 244 |
| 分类 | 关键配置 | 说明 |
|
| 245 |
|------|---------|------|
|
| 246 |
+
| `server` | `host`, `port`, `proxy_api_key` | 服务监听地址与 API 密钥(见下方说明) |
|
| 247 |
| `api` | `base_url`, `timeout_seconds` | 上游 API 地址与请求超时 |
|
| 248 |
+
| `client` | `app_version`, `build_number`, `chromium_version` | 模拟的 Codex Desktop 版本与 Chromium 版本 |
|
| 249 |
| `model` | `default`, `default_reasoning_effort` | 默认模型与推理强度 |
|
| 250 |
| `auth` | `rotation_strategy`, `rate_limit_backoff_seconds` | 轮换策略与限流退避 |
|
| 251 |
+
| `tls` | `curl_binary`, `impersonate_profile`, `proxy_url` | TLS 伪装与代理配置 |
|
| 252 |
+
|
| 253 |
+
### API 密钥 (proxy_api_key)
|
| 254 |
+
|
| 255 |
+
在 `config/default.yaml` 中设置客户端访问代理时使用的 API Key:
|
| 256 |
+
|
| 257 |
+
```yaml
|
| 258 |
+
server:
|
| 259 |
+
proxy_api_key: "pwd" # 自定义密钥,客户端请求时使用此值
|
| 260 |
+
# proxy_api_key: null # 设为 null 则自动生成 codex-proxy-xxxx 格式的密钥
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
- **自定义密钥**:设置为任意字符串(如 `"pwd"`),客户端使用 `Authorization: Bearer pwd` 访问
|
| 264 |
+
- **自动生成**:设为 `null`,代理会根据账号信息自动生成一个 `codex-proxy-` 前缀的哈希密钥
|
| 265 |
+
- 当前密钥始终显示在控制面板(`http://localhost:8080`)的 API Configuration 区域
|
| 266 |
|
| 267 |
### 环境变量覆盖
|
| 268 |
|
| 269 |
| 环境变量 | 覆盖配置 |
|
| 270 |
|---------|---------|
|
| 271 |
| `PORT` | `server.port` |
|
| 272 |
+
| `CODEX_PLATFORM` | `client.platform` |
|
| 273 |
+
| `CODEX_ARCH` | `client.arch` |
|
| 274 |
+
| `HTTPS_PROXY` | `tls.proxy_url` |
|
| 275 |
|
| 276 |
## 📡 API 端点一览 (API Endpoints)
|
| 277 |
|
| 278 |
| 端点 | 方法 | 说明 |
|
| 279 |
|------|------|------|
|
| 280 |
+
| `/v1/chat/completions` | POST | 聊天补全 — OpenAI 格式(核心端点) |
|
| 281 |
+
| `/v1/messages` | POST | 聊天补全 — Anthropic 格式 |
|
| 282 |
| `/v1/models` | GET | 可用模型列表 |
|
| 283 |
| `/health` | GET | 健康检查 |
|
| 284 |
+
| `/auth/accounts` | GET | 账号列表(`?quota=true` 含配额) |
|
| 285 |
+
| `/auth/accounts/login` | GET | OAuth 登录入口 |
|
| 286 |
| `/debug/fingerprint` | GET | 调试:查看当前伪装头信息 |
|
| 287 |
|
| 288 |
## 🔧 命令 (Commands)
|
|
|
|
| 292 |
| `npm run dev` | 开发模式启动(热重载) |
|
| 293 |
| `npm run build` | 编译 TypeScript 到 `dist/` |
|
| 294 |
| `npm start` | 运行编译后的生产版本 |
|
| 295 |
+
| `npm run update` | 手动触发完整更新流水线 |
|
| 296 |
|
| 297 |
## 📋 系统要求 (Requirements)
|
| 298 |
|
| 299 |
+
- **Node.js** 18+(推荐 20+)
|
| 300 |
+
- **curl** — 系统自带即可;`npm install` 自动下载 curl-impersonate 获得完整 Chrome TLS 伪装
|
| 301 |
+
- **ChatGPT 账号** — 普通免费账号即可
|
| 302 |
+
- **Docker**(可选) — 推荐使用 Docker 部署
|
| 303 |
|
| 304 |
## ⚠️ 注意事项 (Notes)
|
| 305 |
|
| 306 |
- Codex API 为**流式输出专用**,设置 `stream: false` 时代理会内部流式收集后返回完整 JSON
|
| 307 |
+
- 本项目依赖 Codex Desktop 的公开接口,上游版本更新时会自动检测并更新指纹
|
| 308 |
+
- 建议在 **Linux / macOS** 上部署以获得完整 TLS 伪装能力(Windows 下 curl-impersonate 暂不可用,降级为系统 curl)
|
| 309 |
+
- `config/default.yaml` 中的注释在自动更新后会丢失(使用结构化 YAML 写入)
|
| 310 |
|
| 311 |
## 📄 许可协议 (License)
|
| 312 |
|
config/default.yaml
CHANGED
|
@@ -27,7 +27,7 @@ auth:
|
|
| 27 |
server:
|
| 28 |
host: "::"
|
| 29 |
port: 8080
|
| 30 |
-
proxy_api_key:
|
| 31 |
|
| 32 |
environment:
|
| 33 |
default_id: null
|
|
|
|
| 27 |
server:
|
| 28 |
host: "::"
|
| 29 |
port: 8080
|
| 30 |
+
proxy_api_key: "pwd"
|
| 31 |
|
| 32 |
environment:
|
| 33 |
default_id: null
|