{"id":20197136,"url":"https://github.com/zai-kun/reverse-engineered-chatgpt","last_synced_at":"2025-04-05T11:07:45.143Z","repository":{"id":200801773,"uuid":"706064798","full_name":"Zai-Kun/reverse-engineered-chatgpt","owner":"Zai-Kun","description":"Unofficial reverse-engineered ChatGPT API in Python","archived":false,"fork":false,"pushed_at":"2024-04-07T08:59:54.000Z","size":131,"stargazers_count":236,"open_issues_count":16,"forks_count":33,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-07-30T09:38:40.074Z","etag":null,"topics":["ai","api","chatgpt","chatgpt-api","chatgpt-free","openai","openai-chatgpt","python","reverse-engineering"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zai-Kun.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-17T08:34:04.000Z","updated_at":"2024-07-29T16:23:11.000Z","dependencies_parsed_at":"2023-10-26T20:36:58.831Z","dependency_job_id":"2d57d94c-fb8a-43cb-879c-0fa13728b42f","html_url":"https://github.com/Zai-Kun/reverse-engineered-chatgpt","commit_stats":null,"previous_names":["zai-kun/reverse-engineered-chatgpt"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zai-Kun%2Freverse-engineered-chatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zai-Kun%2Freverse-engineered-chatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zai-Kun%2Freverse-engineered-chatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zai-Kun%2Freverse-engineered-chatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zai-Kun","download_url":"https://codeload.github.com/Zai-Kun/reverse-engineered-chatgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325693,"owners_count":20920714,"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":["ai","api","chatgpt","chatgpt-api","chatgpt-free","openai","openai-chatgpt","python","reverse-engineering"],"created_at":"2024-11-14T04:27:31.852Z","updated_at":"2025-04-05T11:07:45.124Z","avatar_url":"https://github.com/Zai-Kun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/Zai-Kun/reverse-engineered-chatgpt\"\u003e  \u003c/a\u003e\n\n\u003ch1 align=\"center\"\u003eReverse Engineered \u003ca href=\"https://openai.com/blog/chatgpt\"\u003eChatGPT\u003c/a\u003e API\u003c/h1\u003e\n\n  \u003cp align=\"center\"\u003e\n    Use OpenAI ChatGPT in your Python code without an API key\n\n[![Stargazers][stars-badge]][stars-url]\n[![Forks][forks-badge]][forks-url]\n[![Discussions][discussions-badge]][discussions-url]\n[![Issues][issues-badge]][issues-url]\n[![MIT License][license-badge]][license-url]\n\n  English | [简体中文](./docs/zh-README.md)\n\n  \u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Zai-Kun/reverse-engineered-chatgpt\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/Zai-Kun/reverse-engineered-chatgpt/issues\"\u003eReport Bug\u003c/a\u003e\n    |\n    \u003ca href=\"https://github.com/Zai-Kun/reverse-engineered-chatgpt/discussions\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#inspiration\"\u003eInspiration\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#how-it-works\"\u003eHow it works\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#built-using\"\u003eBuilt using\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#obtaining-session-token\"\u003eObtaining Session Token\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\n        \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#basic-example\"\u003eExample Usage\u003c/a\u003e\u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n## About The Project\n\nThis 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.\n\nThis can be useful if you want to use ChatGPT API without a [ChatGPT Plus](https://openai.com/blog/chatgpt-plus) account.\n\n### Inspiration\n\nChatGPT 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.\n\n### How it works\n\n[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.\n\n### Built Using\n\n- [![Python][python-badge]][python-url]\n\n## Getting Started\n\n### Prerequisites\n\n- Python \u003e= 3.9\n\n### Installation\n\n```sh\npip install re-gpt\n```\n\n## Usage\n\n### Basic example\n\n```python\nfrom re_gpt import SyncChatGPT\n\nsession_token = \"__Secure-next-auth.session-token here\"\nconversation_id = None # conversation ID here\n\n\nwith SyncChatGPT(session_token=session_token) as chatgpt:\n    prompt = input(\"Enter your prompt: \")\n\n    if conversation_id:\n        conversation = chatgpt.get_conversation(conversation_id)\n    else:\n        conversation = chatgpt.create_new_conversation()\n\n    for message in conversation.chat(prompt):\n        print(message[\"content\"], flush=True, end=\"\")\n\n```\n\n### Basic async example\n\n```python\nimport asyncio\nimport sys\n\nfrom re_gpt import AsyncChatGPT\n\nsession_token = \"__Secure-next-auth.session-token here\"\nconversation_id = conversation_id = None # conversation ID here\n\nif sys.version_info \u003e= (3, 8) and sys.platform.lower().startswith(\"win\"):\n    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())\n\n\nasync def main():\n    async with AsyncChatGPT(session_token=session_token) as chatgpt:\n        prompt = input(\"Enter your prompt: \")\n\n        if conversation_id:\n            conversation = chatgpt.get_conversation(conversation_id)\n        else:\n            conversation = chatgpt.create_new_conversation()\n\n        async for message in conversation.chat(prompt):\n            print(message[\"content\"], flush=True, end=\"\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## More Examples\n\nFor a more complex example, check out the [examples](/examples) folder in the repository.\n\n### Obtaining The Session Token\n\n1. Go to \u003chttps://chat.openai.com/chat\u003e and log in or sign up.\n2. Open the developer tools in your browser.\n3. Go to the `Application` tab and open the `Cookies` section.\n4. Copy the value for `__Secure-next-auth.session-token` and save it.\n\n## TODO\n\n- [x] Add more examples\n- [ ] Add better error handling\n- [x] Implement a function to retrieve all ChatGPT chats\n- [ ] Improve documentation\n\n## Contributing\n\nContributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request.\nDon't forget to give the project a star! Thanks again!\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nDistributed under the Apache License 2.0. See [`LICENSE`](https://github.com/Zai-Kun/reverse-engineered-chatgpt/blob/main/LICENSE) for more information.\n\n## Contact/Bug report\n\nZai-Kun - [Discord Server](https://discord.gg/ymcqxudVJG)\n\nRepo Link: \u003chttps://github.com/Zai-Kun/reverse-engineered-chatgpt\u003e\n\n## Acknowledgments\n\n- [sudoAlphaX (for writing this readme)](https://github.com/sudoAlphaX)\n\n- [yifeikong (curl-cffi module)](https://github.com/yifeikong/curl_cffi)\n\n- [acheong08 (implementation to obtain arkose_token)](https://github.com/acheong08/funcaptcha)\n\n- [pyca (cryptography module)](https://github.com/pyca/cryptography/)\n\n- [Legrandin (pycryptodome module)](https://github.com/Legrandin/pycryptodome/)\n\n- [othneildrew (README Template)](https://github.com/othneildrew)\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\n[forks-badge]: https://img.shields.io/github/forks/Zai-Kun/reverse-engineered-chatgpt\n[forks-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/network/members\n[stars-badge]: https://img.shields.io/github/stars/Zai-Kun/reverse-engineered-chatgpt\n[stars-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/stargazers\n[issues-badge]: https://img.shields.io/github/issues/Zai-Kun/reverse-engineered-chatgpt\n[issues-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/issues\n[discussions-badge]: https://img.shields.io/github/discussions/Zai-Kun/reverse-engineered-chatgpt\n[discussions-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/discussions\n[python-badge]: https://img.shields.io/badge/Python-blue?logo=python\u0026logoColor=yellow\n[python-url]: https://www.python.org/\n[license-badge]: https://img.shields.io/github/license/Zai-Kun/reverse-engineered-chatgpt\n[license-url]: https://github.com/Zai-Kun/reverse-engineered-chatgpt/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzai-kun%2Freverse-engineered-chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzai-kun%2Freverse-engineered-chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzai-kun%2Freverse-engineered-chatgpt/lists"}