ChatGPT HTTP API Client with CLI
Project description
ChatGPT API
Unofficial API client and CLI for ChatGPT. Based on httpx
, it uses only HTTP requests to communicate.
This project uses Typer with Rich for CLI, so responses are looking good (markdown is supported):
Installation
pip install chatgpt-api
Usage
As a Command Line Interface
Setup
Required to authenticate. In this step you have to provide session key.
chatgpt setup
Start chatting
chatgpt start
As an API
ChatGPT
class inherits from httpx.Client
Recommended usage:
from chatgpt.api import ChatGPT
with ChatGPT(session_key="your-session-key") as chat:
response = chat.send_message("Hello!")
print(response.content)
Without context manager you have to explicitly authenticate:
from chatgpt.api import ChatGPT
chat = ChatGPT(session_key="your-session-key")
chat.authenticate()
chat.send_message("Hello!")
chat.close()
How to acquire session key?
After you log in to ChatGPT in your browser, get value of __Secure-next-auth.session-token
cookie. In this project, this is named as a "session key".
Chrome instruction
- Open ChromeDevTools (F12).
- Click on "Application" tab.
- Click on "Cookies", on the left bar.
- Copy the value of
__Secure-next-auth.session-token
:
Now, you can use it in CLI or directly from Python code.
License
Distributed under the MIT License. See LICENSE
for more information.
Disclaimer
This is a personal project, not affiliated in any way with OpenAI. If you have any objections, please contact me.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for chatgpt_api-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2221d89f2703b19e71ba4c6d2b12607f5df6264a56fdb8f7dad4ac39dd7066b4 |
|
MD5 | 9932437d72b2e9ebb84ae5ba205538ae |
|
BLAKE2b-256 | ab9478d60dae4729b84377fecbee242da91daa921d1fc07d0c4883308bd58a36 |