AIChatGPT Team 帮助中心
返回帮助中心

CLI Proxy API

通过 CLI Proxy 将 ChatGPT Team 转换为 OpenAI 兼容的本地 API,可以在任何支持 OpenAI API 的应用中 (如 Cursor、沉浸式翻译、Bob 翻译等)直接使用。

前置要求

  • • 已登录 ChatGPT Team 账号
  • • 安装 Go 1.21+ 或使用预编译二进制文件
  • • 稳定可访问 ChatGPT 的网络环境(或配置代理)
1

安装 CLI Proxy 工具

选择适合你的 CLI Proxy 方案。推荐使用 `go-chatgpt-api` 或 `chatgpt-to-api` 等开源项目,通过命令行将 ChatGPT 暴露为 OpenAI 兼容的 API 接口。

bash
# 以 go-chatgpt-api 为例
git clone https://github.com/xqdoo00o/ChatGPT-to-API
cd ChatGPT-to-API
go build -o chatgpt-proxy .
2

获取 Session Token

登录 ChatGPT Team 账号,打开浏览器开发者工具(F12)→ Application → Cookies → chatgpt.com,复制 __Secure-next-auth.session-token 的值。

bash
# 或者直接访问以下地址获取 Access Token
https://chatgpt.com/api/auth/session

# 找到 accessToken 字段,格式类似:
# eyJhbGci...(很长的字符串)
3

配置并启动代理服务

将 Session Token 配置到 CLI Proxy 中,然后启动本地代理服务。默认监听 8080 端口,你可以通过 -port 参数修改。

bash
# 设置环境变量
export CHATGPT_SESSION_TOKEN="your-session-token-here"

# 启动服务(默认 http://localhost:8080)
./chatgpt-proxy

# 指定端口
./chatgpt-proxy -port 9090
4

使用 OpenAI 兼容 API

服务启动后,将你原本请求 api.openai.com 的地址替换为本地代理地址,使用任意 API Key(如 fakekey)即可调用。

python
# Python 示例
import openai

client = openai.OpenAI(
    api_key="fakekey",
    base_url="http://localhost:8080/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "你好"}]
)
print(response.choices[0].message.content)
5

选择 Team 工作空间

如果你的账号有多个工作空间,在启动代理时需要指定 Team 工作空间的 Account ID,否则默认使用个人空间。

bash
# 方式一:通过环境变量指定
export CHATGPT_ACCOUNT_ID="your-team-account-id"

# 方式二:在请求头中指定
curl http://localhost:8080/v1/chat/completions \
  -H "ChatGPT-Account-ID: your-team-account-id" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hi"}]}'

常见使用场景

Cursor / VS Code AI 扩展
沉浸式翻译
OpenAI Python/Node SDK
Bob 翻译 / 划词翻译
LangChain / AutoGPT
自定义 AI 应用