Reverse Engineered ChatGPT API
About The Project
The "Reverse Engineered ChatGPT API" project offers a unique way to use OpenAI's ChatGPT in your Python code without needing an official API key. This comes in handy for users who want to leverage the ChatGPT's capabilities without the need for a ChatGPT Plus account, which otherwise would demand a monthly subscription.
Inspiration
Typically, interfacing with ChatGPT via Python requires an API key available only through a ChatGPT Plus account costing $20/month (as of November 5, 2023). In contrast, the ChatGPT web interface can be accessed freely. This project was inspired to bridge that gap by enabling Python code to interact directly with the free ChatGPT web interface, eliminating the API key requirement.
How It Works
The project utilizes reverse-engineering techniques to mimic the requests made to ChatGPT's web interface and integrates these into Python scripts. This simulation allows executing queries in Python as if they were initiated by a user manually on the website, thus negating the need for an API key and any associated costs.
Built Using
This project is primarily built using Python, a versatile and widely-used programming language.
Getting Started
Prerequisites
Ensure that Python version 3.9 or higher is installed on your system to use this project.
Installation
To integrate this project into your Python environment, simply run the command:
pip install re-gpt
Usage
Basic Example
In a Python script, you can use the following sample code to interact with ChatGPT:
from re_gpt import SyncChatGPT
session_token = "__Secure-next-auth.session-token here"
conversation_id = None # your conversation ID
with 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="")
For handling asynchronous tasks, this example can be adapted to use AsyncChatGPT
.
Obtaining The Session Token
To utilize this project, a session token from ChatGPT's web interface is necessary. Follow these steps:
- Access the ChatGPT site and log in.
- Open developer tools in your browser.
- Navigate to the
Application
tab and locate theCookies
section. - Copy the
__Secure-next-auth.session-token
value.
Roadmap and Future Enhancements
The project has plans to include more examples, enhance error handling, and improve documentation in its future iterations.
Contributing
Community contributions are welcome. If you wish to contribute, consider forking the repository and submitting a pull request with your enhancements.
License
This project is licensed under the Apache License 2.0, offering freedom for use, distribution, and modification.
Contact
For issues and discussions, connect with the community through the Discord Server or check out the project repository.
Acknowledgments
The project owes its development to various contributors and modules, including curl-cffi
, cryptography
, and more, as well as the community for continual support and improvement suggestions.