{"id":13645687,"url":"https://github.com/mufeng510/free-chatgpt-api","last_synced_at":"2025-04-21T17:31:19.384Z","repository":{"id":199393950,"uuid":"702784364","full_name":"mufeng510/Free-ChatGPT-API","owner":"mufeng510","description":"基于pandora的ChatGPT API，实现了pool token的自动更新","archived":false,"fork":false,"pushed_at":"2024-01-15T09:38:35.000Z","size":22549,"stargazers_count":134,"open_issues_count":1,"forks_count":33,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-09T19:39:17.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mufeng510.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-10T02:30:06.000Z","updated_at":"2024-10-31T12:03:43.000Z","dependencies_parsed_at":"2024-08-02T01:38:28.527Z","dependency_job_id":null,"html_url":"https://github.com/mufeng510/Free-ChatGPT-API","commit_stats":null,"previous_names":["mufeng510/free-chatgpt-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mufeng510%2FFree-ChatGPT-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mufeng510%2FFree-ChatGPT-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mufeng510%2FFree-ChatGPT-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mufeng510%2FFree-ChatGPT-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mufeng510","download_url":"https://codeload.github.com/mufeng510/Free-ChatGPT-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250100363,"owners_count":21374926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:39.709Z","updated_at":"2025-04-21T17:31:17.927Z","avatar_url":"https://github.com/mufeng510.png","language":null,"funding_links":[],"categories":["Openai"],"sub_categories":[],"readme":"# 基于pandora的ChatGPT API\n\n## 说明\n\n感谢[pandora](https://github.com/pandora-next)项目，这一次真正实现了ChatGPT自由。本项目主要实现了根据账号密码自动获取accessToken并更新至pool-token。初始脚本来源于旧的pandora，该库被删除，无法添加链接，这个脚本是我进行修改过后的，使用更方便。本人也是小白一枚，欢迎大家一起补充完善。\n\n建了一个Q群：698974728，有问题可以在这里说\n\n2023/12/11 重写了脚本，不再需要Python环境\n\n**如果对您有帮助，请给一个免费的star，谢谢！**\n\n## 写在前面\n\n我们的目标是获得一个 `ChatGPT API Key`，通常是在使用`ChatGPT`的衍生项目时使用，比如[ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)、[gpt_academic](https://github.com/binary-husky/gpt_academic)等。这些项目需要我们提供一个 `API Key` 及其对应的 `APIUrl`。\n\n通过使用本项目的脚本，我们将获得一个 `pk-xxxxxxx` 格式的`api key`。`APIUrl`则为你部署的`PandoraNext`地址\n\n### 大致流程\n\n准备账号密码 =\u003e 获取 `Access Token` =\u003e 获取 `Share Token` =\u003e 获取 `Pool Token`\n\n**`Pool Token` 就是我们最后需要的 `api key`。**\n\n### 简单说明\n\n`Access Token`是 OpenAI 官方的用户鉴权信息，相当于用户的唯一标识了，直接使用`Access Token`和使用官方key一样会扣额度，`Access Token`有效期是14天，所以我们至少要14天运行一次脚本。\n\n`Share Token` 和 `Pool Token` 均是由 pandora 作者提供的服务，与官方无关。`Share Token`可以实现多人共享一个账号，可以进行会话隔离，不会扣除额度，实现了ChatGPT自由。但是`Share Token`依旧存在 `1` 个会话的限制，所以作者提供了 `Pool Token`，使用由最多 `100` 个`Share Token`组合的 `Pool Token` 时会自动轮转，实现了多人同时会话。\n\n更多信息可以查看[pandora文档](https://fakeopen.org/PandoraNext/)\n\n### 文件说明\n\n`demo`目录下存放了各环境的示例，本项目是通过`scripts`下的文件实现功能的。\n\n- `run_job.bat` windows执行脚本的批处理脚本\n- `add_auto_run_job.bat` 添加定时任务的批处理脚本\n- `update_pool_token.*` 实现功能的脚本。\n- `credentials.txt` 存储账号、密码\n- `pool_token.txt` 存储 `Pool Token`\n\n## 使用方法\n\n## 部署PandoraNext\n\n首先你需要参考[PandoraNext文档](https://fakeopen.org/PandoraNext/)进行部署，本项目的脚本无需与PandoraNext在同一位置。如果你怕出问题，就按照demo一样，将本项目的`scripts`文件夹放在`PandoraNext`目录下。\n\n**部署PandoraNext时，你至少应配置`config.json`中的 `bind`,`license_id`、`proxy_api_prefix`**\n```\n示例\n{\n    \"bind\": \"0.0.0.0:8181\",\n    \"license_id\": \"xxxxxxxxxxx\",\n    \"proxy_api_prefix\": \"qqrr123123\",\n}\n```\n\n我们在使用 `api key` 时需要将反代url设置为`http(s)://\u003cbind\u003e/\u003cproxy_api_prefix\u003e`\n\n如: `http://127.0.0.1:8181/qqrr123123`\n\n### 自动更新pool token脚本\n\n1. 下载[scripts](https://github.com/mufeng510/Free-ChatGPT-API/tree/master/demo/)到你本地\n\n2. 打开`update_pool_token`文件，修改`$api_url`为`http(s)://\u003cbind\u003e/\u003cproxy_api_prefix\u003e`。\n\n3. 新建`credentials.txt`并设置内容为账号密码，一行一个，账号密码用逗号分隔\n\n```\nxxx@outlook.com,xxxxxx\nxxx@outlook.com,xxxxxx\n```\n\n4. 新建`pool_token.txt`并设置内容为你的pool tohen (可选，没有会自动生成)\n\n```\npk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\npool tohen设置一次后就不会再变了，以后添加修改账号密码只需要执行一次脚本就行了。\n\n5. windows执行`run_job.bat` 即可，linux 执行`bash update_pool_token.sh`，\n\n如果缺少权限先执行\n\nwin: `Set-ExecutionPolicy RemoteSigned`\n\nlinux: `chmod +x update_pool_token.sh`。 \n\npool tohen最后会保存到`pool_token.txt`。\n\n\u003cdetails\u003e \u003csummary\u003epython额外要做的（在上述步骤之前）\u003c/summary\u003e\n\n1. 安装python环境\n\n方法一：下载[python](https://www.python.org/downloads/)安装并设置环境变量。\n\n方法二：使用`miniconda`。\n\n- 在终端中执行：\n```\n# 使用scoop安装miniconda3 (没有scoop请手动安装miniconda)\nscoop install miniconda3\n# 创建pandora专用的环境\nconda create -n pool python=3.10\nconda init bash\nconda activate pool\n```\n\n-  打开`run_job.bat`，在`python update_pool_token.py`之前添加`call conda activate pool`\n![conda](https://github.com/mufeng510/Free-ChatGPT-API/raw/master/images/5.png)\n\n2. 安装依赖\n\n```\npip install pandora-chatgpt\n```\n\u003c/details\u003e\n\n## 在其他项目中使用 pool token\n\n### [ChatGPT-Next-Web](https://github.com/Yidadaa/ChatGPT-Next-Web)\n\n```\nOPENAI_API_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'\nBASE_URL: 'http(s)://\u003cbind\u003e/\u003cproxy_api_prefix\u003e'\n```\n\n### [gpt_academic](https://github.com/binary-husky/gpt_academic)\n\n```\nAPI_KEY: 'pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx'\nCUSTOM_API_KEY_PATTERN : 'pk-[a-zA-Z0-9-]+$$'\nAPI_URL_REDIRECT : '{\"https://api.openai.com/v1/chat/completions\": \"http(s)://\u003cbind\u003e/\u003cproxy_api_prefix\u003e/v1/chat/completions\"}'\n```\n\n## 定时执行\n\n**windows:**\n\n运行`add_auto_run_job.bat`,默认每周二执行，想修改可以发给GPT说明你的需求进行改，添加好后可以运行一次试试有没有问题。\n\n![测试](https://github.com/mufeng510/Free-ChatGPT-API/raw/master/images/4.png)\n\n**linux:**\n\n执行`bash add_auto_run_job.sh`，每隔7天执行一次，需要删除可执行 `bash delete_auto_run_job.sh`。可在 `crontab -e` 查看\n\n### 共享站\n\nPandoraNext提供了一个功能等同[chat-shared3.zhile.io](https://chat-shared3.zhile.io/)的共享站，如果你需要保存`access_token`以供共享站使用，需要做以下修改\n\n1. 将本项目脚本放置`PandoraNext`的子目录下，如本项目demo一样\n\n2. 打开`update_pool_token`文件，取消 `Run` 方法中的 `Save-Tokens` 的注释\n\n3. 运行脚本","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmufeng510%2Ffree-chatgpt-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmufeng510%2Ffree-chatgpt-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmufeng510%2Ffree-chatgpt-api/lists"}