or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdchat-interface.mdconfiguration.mdindex.md
tile.json

tessl/pypi-chatgptpy

TLS-based ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/chatgptpy@1.0.x

To install, run

npx @tessl/cli install tessl/pypi-chatgptpy@1.0.0

index.mddocs/

ChatGPT Python API

A 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.

Package Information

  • Package Name: chatgptpy
  • Package Type: pypi
  • Language: Python
  • Installation: pip install chatgptpy

Core Imports

from pychatgpt import Chat, Options

Authentication utilities:

from pychatgpt import OpenAI

Basic Usage

from 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()

Architecture

The library is built around three main components:

  • Chat Class: Main interface for ChatGPT conversations with session management, authentication handling, and conversation tracking
  • Options Class: Configuration container for customizing chat behavior including proxies, logging, conversation persistence, and moderation settings
  • OpenAI Module: Authentication and token management utilities that handle the complex TLS-based login flow, token creation, and automatic refresh

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.

Capabilities

Chat Interface

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: ...

Chat Interface

Configuration Options

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 None

Configuration

Authentication Management

Token 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): ...

Authentication

Types

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): ...