Skip to content

Remove unofficial api #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,15 @@ Some unique features have been added:

## Introduction

Supports dual models, provides two unofficial `ChatGPT API` methods:
Uses the official `OpenAI API` to access `ChatGPT`:

| Method | Free? | Reliability | Quality |
| --------------------------------------------- | ------ | ----------- | ------- |
| `ChatGPTAPI(gpt-3.5-turbo-0301)` | No | Reliable | Relatively clumsy |
| `ChatGPTUnofficialProxyAPI(Web accessToken)` | Yes | Relatively unreliable | Smart |

Comparison:
1. `ChatGPTAPI` uses `gpt-3.5-turbo-0301` to simulate `ChatGPT` through the official `OpenAI` completion `API` (the most reliable method, but it is not free and does not use models specifically tuned for chat).
2. `ChatGPTUnofficialProxyAPI` accesses `ChatGPT`'s backend `API` via an unofficial proxy server to bypass `Cloudflare` (uses the real `ChatGPT`, is very lightweight, but depends on third-party servers and has rate limits).
`ChatGPTAPI` uses `gpt-4.1` through the official `OpenAI` completion `API` (requires an API key).

[Details](https://github.com/Chanzhaoyu/chatgpt-web/issues/138)

Switching Methods:
Setup:
1. Go to the `service/.env.example` file and copy the contents to the `service/.env` file.
2. For `OpenAI API Key`, fill in the `OPENAI_API_KEY` field [(Get apiKey)](https://platform.openai.com/overview).
3. For `Web API`, fill in the `OPENAI_ACCESS_TOKEN` field [(Get accessToken)](https://chat.openai.com/api/auth/session).
4. When both are present, `OpenAI API Key` takes precedence.

Reverse Proxy:

Available when using `ChatGPTUnofficialProxyAPI`.[Details](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)

```shell
# service/.env
API_REVERSE_PROXY=
```
2. Fill in the `OPENAI_API_KEY` field with your OpenAI API Key [(Get apiKey)](https://platform.openai.com/overview).

Environment Variables:

Expand Down Expand Up @@ -152,18 +134,15 @@ If you have not installed `pnpm` before:
npm install pnpm -g
```

### Fill in the Keys
### Fill in the API Key

Get `Openai Api Key` or `accessToken` and fill in the local environment variables [jump](#introduction)
Get your `OpenAI API Key` and fill in the local environment variables [jump](#introduction)

```
# service/.env file

# OpenAI API Key - https://platform.openai.com/overview
OPENAI_API_KEY=

# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
OPENAI_ACCESS_TOKEN=
```

## Install Dependencies
Expand Down Expand Up @@ -205,11 +184,9 @@ pnpm dev

#### Docker Parameter Example

- `OPENAI_API_KEY` one of two
- `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present
- `OPENAI_API_KEY` required
- `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set
- `OPENAI_API_MODEL` `ChatGPTAPI` OR `ChatGPTUnofficialProxyAPI`
- `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction)
- `OPENAI_API_MODEL` optional, specify the model to use
- `AUTH_SECRET_KEY` Access Password,optional
- `TIMEOUT_MS` timeout, in milliseconds, optional
- `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT
Expand Down
49 changes: 20 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,17 @@
- [License](#license)
## 介绍

支持双模型,提供了两种非官方 `ChatGPT API` 方法
使用官方 `OpenAI API` 访问 `ChatGPT`:

| 方式 | 免费? | 可靠性 | 质量 |
| --------------------------------------------- | ------ | ---------- | ---- |
| `ChatGPTAPI(gpt-3.5-turbo-0301)` | 否 | 可靠 | 相对较笨 |
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 相对不可靠 | 聪明 |

对比:
1. `ChatGPTAPI` 使用 `gpt-3.5-turbo` 通过 `OpenAI` 官方 `API` 调用 `ChatGPT`
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(依赖于第三方服务器,并且有速率限制)
`ChatGPTAPI` 使用 `gpt-4.1` 通过 `OpenAI` 官方 `API` 调用 `ChatGPT`(需要 API 密钥)。

警告:
1. 你应该首先使用 `API` 方式
2. 使用 `API` 时,如果网络不通,那是国内被墙了,你需要自建代理,绝对不要使用别人的公开代理,那是危险的。
3. 使用 `accessToken` 方式时反向代理将向第三方暴露您的访问令牌,这样做应该不会产生任何不良影响,但在使用这种方法之前请考虑风险。
4. 使用 `accessToken` 时,不管你是国内还是国外的机器,都会使用代理。默认代理为 [pengzhile](https://github.com/pengzhile) 大佬的 `https://ai.fakeopen.com/api/conversation`,这不是后门也不是监听,除非你有能力自己翻过 `CF` 验证,用前请知悉。[社区代理](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)(注意:只有这两个是推荐,其他第三方来源,请自行甄别)
5. 把项目发布到公共网络时,你应该设置 `AUTH_SECRET_KEY` 变量添加你的密码访问权限,你也应该修改 `index.html` 中的 `title`,防止被关键词搜索到。
1. 使用 `API` 时,如果网络不通,那是国内被墙了,你需要自建代理,绝对不要使用别人的公开代理,那是危险的。
2. 把项目发布到公共网络时,你应该设置 `AUTH_SECRET_KEY` 变量添加你的密码访问权限,你也应该修改 `index.html` 中的 `title`,防止被关键词搜索到。

切换方式
设置方式
1. 进入 `service/.env.example` 文件,复制内容到 `service/.env` 文件
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
3. 使用 `Web API` 请填写 `OPENAI_ACCESS_TOKEN` 字段 [(获取 accessToken)](https://chat.openai.com/api/auth/session)
4. 同时存在时以 `OpenAI API Key` 优先
2. 填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)

环境变量:

Expand Down Expand Up @@ -149,17 +137,14 @@ node -v
npm install pnpm -g
```

### 填写密钥
获取 `Openai Api Key` 或 `accessToken` 并填写本地环境变量 [跳转](#介绍)
### 填写API密钥
获取 `OpenAI API Key` 并填写本地环境变量 [跳转](#介绍)

```
# service/.env 文件

# OpenAI API Key - https://platform.openai.com/overview
OPENAI_API_KEY=

# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
OPENAI_ACCESS_TOKEN=
```

## 安装依赖
Expand Down Expand Up @@ -199,15 +184,10 @@ pnpm dev

`API` 可用:

- `OPENAI_API_KEY` 和 `OPENAI_ACCESS_TOKEN` 二选一
- `OPENAI_API_KEY` 必填
- `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com`
- `OPENAI_API_DISABLE_DEBUG` 设置接口关闭 debug 日志,可选,默认:empty 不关闭

`ACCESS_TOKEN` 可用:

- `OPENAI_ACCESS_TOKEN` 和 `OPENAI_API_KEY` 二选一,同时存在时,`OPENAI_API_KEY` 优先
- `API_REVERSE_PROXY` 设置反向代理,可选,默认:`https://ai.fakeopen.com/api/conversation`,[社区](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)(注意:只有这两个是推荐,其他第三方来源,请自行甄别)

通用:

- `AUTH_SECRET_KEY` 访问权限密钥,可选
Expand All @@ -223,6 +203,17 @@ pnpm dev

#### Docker 参数示例

- `OPENAI_API_KEY` 必填
- `OPENAI_API_BASE_URL` 可选,设置接口地址,默认:`https://api.openai.com`
- `OPENAI_API_MODEL` 可选,指定使用的模型
- `AUTH_SECRET_KEY` 访问密码,可选
- `TIMEOUT_MS` 超时,单位毫秒,可选
- `SOCKS_PROXY_HOST` 可选,与 SOCKS_PROXY_PORT 一起使用
- `SOCKS_PROXY_PORT` 可选,与 SOCKS_PROXY_HOST 一起使用
- `SOCKS_PROXY_USERNAME` 可选,与 SOCKS_PROXY_HOST 和 SOCKS_PROXY_PORT 一起使用
- `SOCKS_PROXY_PASSWORD` 可选,与 SOCKS_PROXY_HOST 和 SOCKS_PROXY_PORT 一起使用
- `HTTPS_PROXY` 可选,支持 http,https, socks5

![docker](./docs/docker.png)

#### Docker build & Run
Expand Down
11 changes: 4 additions & 7 deletions service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"scripts": {
"start": "tsx ./src/index.ts",
"dev": "tsx watch ./src/index.ts",
"dev": "tsx watch --inspect ./src/index.ts",
"prod": "node --import tsx/esm ./build/index.js",
"prod-node18": "node --loader tsx/esm ./build/index.js",
"build": "pnpm clean && tsc && pnpm copy",
Expand All @@ -29,22 +29,19 @@
},
"dependencies": {
"axios": "^1.8.4",
"chatgpt": "npm:@chatgptweb/[email protected]",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"express": "^5.1.0",
"express-rate-limit": "^6.7.0",
"file-type": "^19.0.0",
"gpt-token": "^0.0.5",
"https-proxy-agent": "^5.0.1",
"https-proxy-agent": "^7.0.6",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.1.2",
"mongodb": "^6.6.2",
"multer": "1.4.5-lts.1",
"node-fetch": "^3.3.0",
"nodemailer": "^6.9.13",
"openai": "^4.96.0",
"request-ip": "^3.3.0",
"socks-proxy-agent": "^7.0.0",
"speakeasy": "^2.0.0",
"tsx": "^4.7.0"
},
Expand All @@ -53,7 +50,7 @@
"@types/express": "^5.0.1",
"@types/jsonwebtoken": "^9.0.5",
"@types/multer": "^1.4.11",
"@types/node": "^18.14.6",
"@types/node": "^22.15.3",
"@types/nodemailer": "^6.4.14",
"@types/request-ip": "^0.0.41",
"@types/speakeasy": "^2.0.10",
Expand Down
Loading