ChatGPT HTTP API Client and CLI
💻 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.
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.
pip install chatgpt-api
As a Command Line Interface
Required to authenticate. In this step you have to provide session key.
As an API
ChatGPT class inherits from
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".
- Open ChromeDevTools (F12).
- Click on "Application" tab.
- Click on "Cookies", on the left bar.
- Copy the value of
Now, you can use it in CLI or directly from Python code.
Distributed under the MIT License. See
LICENSE for more information.
This is a personal project, not affiliated in any way with OpenAI. If you have any objections, please contact me.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for chatgpt_api-0.2.1-py3-none-any.whl