TLS-based ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Session configuration for customizing chat behavior, including proxy settings, conversation tracking, logging control, and moderation bypass options.
Configuration container that controls various aspects of the chat session including networking, persistence, and behavior settings.
class Options:
"""
Configuration options for Chat sessions.
All attributes have sensible defaults and can be modified after instantiation.
"""
def __init__(self):
self.log: bool = True
self.proxies: str or dict or None = None
self.track: bool or None = False
self.verify: bool = True
self.pass_moderation: bool = False
self.chat_log: str or None = None
self.id_log: str or None = None
def __repr__(self):
return f"<Options log={self.log} proxies={self.proxies} track={self.track} " \
f"verify={self.verify} pass_moderation={self.pass_moderation} " \
f"chat_log={self.chat_log} id_log={self.id_log}>"Enable or disable console output for debugging and monitoring.
log: boolDefault: True
Description: Controls whether the library outputs status messages, errors, and debugging information to stderr.
from pychatgpt import Chat, Options
# Disable logging for production use
options = Options()
options.log = False
chat = Chat(email="user@example.com", password="password", options=options)Configure HTTP/HTTPS proxy for all network requests.
proxies: str or dict or NoneDefault: None
Description: Proxy server configuration. Can be a string URL for both HTTP/HTTPS or a dictionary with separate configurations.
from pychatgpt import Chat, Options
# String proxy (applies to both HTTP and HTTPS)
options = Options()
options.proxies = "http://proxy.example.com:8080"
# Dictionary proxy with separate settings
options.proxies = {
"http": "http://proxy.example.com:8080",
"https": "https://secure-proxy.example.com:8443"
}
chat = Chat(email="user@example.com", password="password", options=options)Enable persistent conversation storage to files.
track: bool or NoneDefault: False
Description: When enabled, automatically saves conversation history and IDs to files, allowing conversation resumption across sessions.
from pychatgpt import Chat, Options
options = Options()
options.track = True # Enable conversation tracking
# Optional: specify custom file paths
options.chat_log = "/path/to/my_conversations.txt"
options.id_log = "/path/to/my_conversation_ids.txt"
chat = Chat(email="user@example.com", password="password", options=options)
# Conversations will be automatically saved
response, prev_id, conv_id = chat.ask("Hello!")
# Later, resume conversation by reading from id_log
with open(options.id_log, 'r') as f:
lines = f.readlines()
if len(lines) >= 2:
previous_convo_id = lines[0].strip()
conversation_id = lines[1].strip()
# Resume conversation
chat_resumed = Chat(
email="user@example.com",
password="password",
options=options,
conversation_id=conversation_id,
previous_convo_id=previous_convo_id
)Control SSL certificate verification for HTTPS requests.
verify: boolDefault: True
Description: Whether to verify SSL certificates when making HTTPS requests to OpenAI endpoints.
Skip OpenAI's content moderation pre-checks.
pass_moderation: boolDefault: False
Description: When False, the library makes a preliminary request to OpenAI's moderation endpoint before sending the actual message. When True, skips this step.
from pychatgpt import Chat, Options
# Skip moderation for faster responses (use with caution)
options = Options()
options.pass_moderation = True
chat = Chat(email="user@example.com", password="password", options=options)Specify custom file path for conversation history storage.
chat_log: str or NoneDefault: None (uses "chat_log.txt" when tracking is enabled)
Description: File path where conversation history is saved when track=True.
Specify custom file path for conversation ID storage.
id_log: str or NoneDefault: None (uses "id_log.txt" when tracking is enabled)
Description: File path where conversation IDs are saved when track=True. This file contains the previous conversation ID and current conversation ID on separate lines.
from pychatgpt import Chat, Options
# Create options with all settings
options = Options()
options.log = True # Enable logging
options.proxies = "http://proxy.example.com:8080" # Use proxy
options.track = True # Enable conversation tracking
options.verify = True # Verify SSL certificates
options.pass_moderation = False # Use moderation pre-checks
options.chat_log = "./conversations.txt" # Custom chat log path
options.id_log = "./conversation_ids.txt" # Custom ID log path
# Create chat with options
chat = Chat(
email="user@example.com",
password="password",
options=options
)
# Use chat normally - all options will be applied
response, prev_id, conv_id = chat.ask("Hello, ChatGPT!")When track=True, the chat log file contains conversation history in this format:
You: Hello, how are you?
Chat GPT: Hello! I'm doing well, thank you for asking. How are you today?
You: I'm doing great! Can you help me with Python?
Chat GPT: Of course! I'd be happy to help you with Python. What specific topic or problem would you like assistance with?The ID log file contains conversation IDs on separate lines:
uuid-of-previous-conversation
uuid-of-current-conversationThese IDs are used to maintain conversation context across sessions.
Install with Tessl CLI
npx tessl i tessl/pypi-chatgptpy