💻 ChatGPT API
Unofficial API client and CLI for ChatGPT.
This project is based on httpx (uses only HTTP) and uses Typer (with Rich) for CLI, so responses are looking good (markdown is supported). Also, It has 100% code coverage unlike other ChatGPT packages.
Status
ChatGPT API often changes. I'm trying to make updates as soon as possible. So, if something is not working properly and you recently didn't upgrade chatgpt-api, try to do this first:
pip install --upgrade chatgpt-api
If that doesn't help, please open an issue.
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_token="your-session-token") 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_token="your-session-token")
chat.authenticate()
response = chat.send_message("Hello!")
print(response.content)
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.
Metadata
Release files for chatgpt-api 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chatgpt-api-0.2.1.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chatgpt_api-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / chatgpt-api-0.2.1.tar.gz
| Download URL | chatgpt-api-0.2.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7daba92d039c43e3fd8fc1d8b62a0b3834b83d307c139162d1f03b4cfaa25681
|
|
BLAKE2b-256 checksum How to use checksums |
d6e1ffc48601f7ec9f821ace4c6640925da703f19958544af6214799385d3086
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / chatgpt_api-0.2.1-py3-none-any.whl
| Download URL | chatgpt_api-0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f55d3ee8652d52ac8baee9ad30d1646764cae651f4e5cfdb12ac386b15d3c318
|
|
BLAKE2b-256 checksum How to use checksums |
7f29f49d1e21dc2d0544d7b35b58a2097624b49b78e9fc182898a1482c326405
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|