TLS-based ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.
npx @tessl/cli install tessl/pypi-chatgptpy@1.0.0A Python library for TLS-based ChatGPT API interaction that automatically handles authentication and token management. This library enables developers to programmatically chat with ChatGPT by providing email/password authentication, automatic access token retrieval and refresh, conversation tracking and resumption, proxy support for network routing, and conversation logging capabilities.
pip install chatgptpyfrom pychatgpt import Chat, OptionsAuthentication utilities:
from pychatgpt import OpenAIfrom pychatgpt import Chat, Options
# Basic chat session
chat = Chat(email="your-email@example.com", password="your-password")
response, previous_id, conversation_id = chat.ask("Hello, how are you?")
print(response)
# Chat with options for proxy and tracking
options = Options()
options.proxies = "http://proxy.example.com:8080"
options.track = True # Enable conversation tracking
options.log = True # Enable console logging
chat = Chat(
email="your-email@example.com",
password="your-password",
options=options
)
# Interactive CLI session
chat.cli_chat()The library is built around three main components:
The authentication flow automatically handles OpenAI's multi-step login process including CSRF tokens, state management, captcha solving when required, and access token caching to avoid repeated logins.
Core conversation functionality including message sending, response handling, conversation context management, and interactive CLI sessions.
class Chat:
def __init__(
self,
email: str,
password: str,
options: Options or None = None,
conversation_id: str or None = None,
previous_convo_id: str or None = None
): ...
def ask(
self,
prompt: str,
previous_convo_id: str or None = None,
conversation_id: str or None = None,
rep_queue: Queue or None = None
) -> Tuple[str or None, str or None, str or None] or None: ...
def cli_chat(self, rep_queue: Queue or None = None) -> None: ...Session configuration including proxy settings, conversation tracking, logging control, and moderation bypass options.
class Options:
def __init__(self): ...
log: bool
proxies: str or dict or None
track: bool or None
verify: bool
pass_moderation: bool
chat_log: str or None
id_log: str or NoneToken management utilities for handling OpenAI authentication, including manual token operations and session validation.
def token_expired() -> bool: ...
def get_access_token() -> Tuple[str or None, str or None]: ...
class Auth:
def __init__(
self,
email_address: str,
password: str,
proxy: str = None
): ...
def create_token(self): ...from queue import Queue
from typing import Tuple
# Exception classes
class PyChatGPTException(Exception):
def __init__(self, message: str): ...
class Auth0Exception(PyChatGPTException):
def __init__(self, message: str): ...
class IPAddressRateLimitException(PyChatGPTException):
def __init__(self, message: str): ...