Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zai-kun/reverse-engineered-chatgpt
Unofficial reverse-engineered ChatGPT API in Python
https://github.com/zai-kun/reverse-engineered-chatgpt
ai api chatgpt chatgpt-api chatgpt-free openai openai-chatgpt python reverse-engineering
Last synced: 3 days ago
JSON representation
Unofficial reverse-engineered ChatGPT API in Python
- Host: GitHub
- URL: https://github.com/zai-kun/reverse-engineered-chatgpt
- Owner: Zai-Kun
- License: apache-2.0
- Created: 2023-10-17T08:34:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-07T08:59:54.000Z (9 months ago)
- Last Synced: 2024-07-30T09:38:40.074Z (5 months ago)
- Topics: ai, api, chatgpt, chatgpt-api, chatgpt-free, openai, openai-chatgpt, python, reverse-engineering
- Language: Python
- Homepage:
- Size: 128 KB
- Stars: 236
- Watchers: 11
- Forks: 33
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Reverse Engineered ChatGPT API
Use OpenAI ChatGPT in your Python code without an API key[![Stargazers][stars-badge]][stars-url]
[![Forks][forks-badge]][forks-url]
[![Discussions][discussions-badge]][discussions-url]
[![Issues][issues-badge]][issues-url]
[![MIT License][license-badge]][license-url]English | [简体中文](./docs/zh-README.md)
Table of Contents
## About The Project
This project can be used to integrate OpenAI's ChatGPT services into your python code. You can use this project to prompt ChatGPT for responses directly from python, without using an official API key.
This can be useful if you want to use ChatGPT API without a [ChatGPT Plus](https://openai.com/blog/chatgpt-plus) account.
### Inspiration
ChatGPT has an official API which can be used to interface your Python code to it, but it needs to be used with an API key. This API key can only be obtained if you have a [ChatGPT Plus](https://openai.com/blog/chatgpt-plus) account, which requires $20/month (as of 05/11/2023). But you can use ChatGPT for free, using the [ChatGPT web interface](https://chat.openai.com/). This project aims to interface your code to ChatGPT web version so you can use ChatGPT in your Python code without using an API key.
### How it works
[ChatGPT](https://chat.openai.com/) web interface's requests have been reverse engineered, and directly integrated into Python requests. Hence, any requests made using this script is a simulated as a request made by a user directly on the website. Hence, it is free and needs no API key.
### Built Using
- [![Python][python-badge]][python-url]
## Getting Started
### Prerequisites
- Python >= 3.9
### Installation
```sh
pip install re-gpt
```## Usage
### Basic example
```python
from re_gpt import SyncChatGPTsession_token = "__Secure-next-auth.session-token here"
conversation_id = None # conversation ID herewith SyncChatGPT(session_token=session_token) as chatgpt:
prompt = input("Enter your prompt: ")if conversation_id:
conversation = chatgpt.get_conversation(conversation_id)
else:
conversation = chatgpt.create_new_conversation()for message in conversation.chat(prompt):
print(message["content"], flush=True, end="")```
### Basic async example
```python
import asyncio
import sysfrom re_gpt import AsyncChatGPT
session_token = "__Secure-next-auth.session-token here"
conversation_id = conversation_id = None # conversation ID hereif sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())async def main():
async with AsyncChatGPT(session_token=session_token) as chatgpt:
prompt = input("Enter your prompt: ")if conversation_id:
conversation = chatgpt.get_conversation(conversation_id)
else:
conversation = chatgpt.create_new_conversation()async for message in conversation.chat(prompt):
print(message["content"], flush=True, end="")if __name__ == "__main__":
asyncio.run(main())
```## More Examples
For a more complex example, check out the [examples](/examples) folder in the repository.
### Obtaining The Session Token
1. Go to and log in or sign up.
2. Open the developer tools in your browser.
3. Go to the `Application` tab and open the `Cookies` section.
4. Copy the value for `__Secure-next-auth.session-token` and save it.## TODO
- [x] Add more examples
- [ ] Add better error handling
- [x] Implement a function to retrieve all ChatGPT chats
- [ ] Improve documentation## Contributing
Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
If you have a suggestion that would make this better, please fork the repo and create a pull request.
Don't forget to give the project a star! Thanks again!1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## License
Distributed under the Apache License 2.0. See [`LICENSE`](https://github.com/Zai-Kun/reverse-engineered-chatgpt/blob/main/LICENSE) for more information.
## Contact/Bug report
Zai-Kun - [Discord Server](https://discord.gg/ymcqxudVJG)
Repo Link:
## Acknowledgments
- [sudoAlphaX (for writing this readme)](https://github.com/sudoAlphaX)
- [yifeikong (curl-cffi module)](https://github.com/yifeikong/curl_cffi)
- [acheong08 (implementation to obtain arkose_token)](https://github.com/acheong08/funcaptcha)
- [pyca (cryptography module)](https://github.com/pyca/cryptography/)
- [Legrandin (pycryptodome module)](https://github.com/Legrandin/pycryptodome/)
- [othneildrew (README Template)](https://github.com/othneildrew)
[forks-badge]: https://img.shields.io/github/forks/Zai-Kun/reverse-engineered-chatgpt
[forks-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/network/members
[stars-badge]: https://img.shields.io/github/stars/Zai-Kun/reverse-engineered-chatgpt
[stars-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/stargazers
[issues-badge]: https://img.shields.io/github/issues/Zai-Kun/reverse-engineered-chatgpt
[issues-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/issues
[discussions-badge]: https://img.shields.io/github/discussions/Zai-Kun/reverse-engineered-chatgpt
[discussions-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/discussions
[python-badge]: https://img.shields.io/badge/Python-blue?logo=python&logoColor=yellow
[python-url]: https://www.python.org/
[license-badge]: https://img.shields.io/github/license/Zai-Kun/reverse-engineered-chatgpt
[license-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/blob/main/LICENSE