Skip to main content

Python SDK for controlling existing ChatGPT web sessions without browser UI.

Project description

chatgpt-web-adapter

CI

Python SDK for controlling existing ChatGPT web sessions without browser UI.

[!WARNING] Not the official OpenAI API. Uses an existing ChatGPT web session. Web backend behavior may change.

chatgpt-web-adapter is a small, dependency-free Python SDK for sending prompts, continuing conversations, reading conversation state, uploading images, and handling selected ChatGPT web workflows from Python.

It is designed for tools that already have valid ChatGPT web-session auth data and want to avoid driving the browser UI.

What This Is

chatgpt-web-adapter wraps the existing ChatGPT web backend behavior used by a logged-in web session. It focuses on reusable transport, request formatting, response parsing, and conversation helpers.

The package intentionally does not include the CLI, localization, auth capture, browser automation, or local chat-history management from webchat-openai-cli.

When It Is Useful

  • controlling long ChatGPT conversations without loading the browser UI
  • building local tools or CLIs on top of an existing ChatGPT web session
  • continuing existing ChatGPT web conversations by id or URL
  • streaming assistant tokens into terminal or app UIs
  • reading messages and polling conversation status from Python
  • uploading images through the web-session flow
  • experimenting with browserless approval workflows

When Not To Use This

  • when you need a stable, documented API contract
  • when you need OpenAI-supported authentication and long-term platform guarantees
  • when browser automation is acceptable and product-level UI behavior matters more than backend reuse
  • when the workflow depends heavily on approval cards or other fast-changing connector behavior
  • when your tool cannot tolerate breakage from undocumented chatgpt.com changes

What This Is Not

chatgpt-web-adapter is not:

  • the official OpenAI API
  • a replacement for the OpenAI Python SDK
  • a login or auth-capture tool
  • a browser automation framework
  • a stable contract for undocumented ChatGPT web internals

Stable vs Experimental

The SDK has two support levels.

Stable core:

  • ChatGPTWebClient.send()
  • send_to_conversation()
  • attach_conversation()
  • get_messages()
  • get_status()
  • wait_until_completed()
  • image upload for multimodal prompts

Experimental features:

  • approve_pending_action()
  • wait_and_approve_pending_actions()
  • send_and_auto_approve()
  • PayloadBuilder
  • validate_payload()
  • send_payload()

The stable core is the main surface intended for building tools on top of an existing ChatGPT web session. Experimental features are exposed because they are useful, but they rely more directly on changing web-client behavior.

Compatibility Policy

  • Stable core APIs are the main compatibility target of the package.
  • Experimental APIs may need faster iteration when the ChatGPT web client changes.
  • A package release does not guarantee that undocumented web behavior on chatgpt.com has remained unchanged.
  • When the site changes, experimental flows are expected to break before the stable core send/continue/read flows.

Known Failure Modes

  • expired or mismatched session auth
    • accessToken, cookies, and headers can drift out of sync
  • changed anti-abuse requirements
    • chat-requirements, proof-of-work, or Turnstile expectations can change
  • changed backend payload schema
    • send/continue flows can fail if required request fields move or change meaning
  • changed SSE response shape
    • token streaming, finish-reason parsing, or conversation-id extraction can break
  • changed conversation payload schema
    • attach, status, model detection, and message extraction depend on unstable fields
  • changed upload flow
    • file creation, upload, or attachment metadata contracts can shift
  • changed approval protocol
    • approval helpers are especially sensitive to connector and web-client changes

Features

  • zero runtime Python dependencies
  • sync ChatGPTWebClient
  • streaming via on_token and structured events via on_event
  • conversation continuation with returned conversation metadata
  • attach/read/status helpers for existing conversations
  • auth_data.json and .env auth loading
  • image uploads from local paths, Path, URL, data URI, or raw bytes
  • experimental browserless tool-approval helpers for web-agent flows
  • experimental raw payload escape hatch for advanced users
  • local curl-based transport for compatibility with stock Python

Requirements

  • Python 3.10+
  • system curl available in PATH
  • valid auth_data.json with accessToken, or an optional .env fallback with accessToken

Install

python -m pip install chatgpt-web-adapter

For local development and tests:

python -m pip install -e .[test]
pytest -q

Quick Start

from chatgpt_web_adapter import ChatGPTWebClient

client = ChatGPTWebClient(auth_file="auth_data.json")

response = client.send(
    "Give me a short summary of this project.",
    model="gpt-4o-mini",
)

print(response.text)

Authentication at a Glance

chatgpt-web-adapter does not log you in and does not capture auth by itself. It only reuses existing chatgpt.com web-session data.

Recommended auth_data.json shape:

{
  "accessToken": "eyJhbGciOi...",
  "cookies": {
    "__Secure-next-auth.session-token": "..."
  },
  "headers": {
    "user-agent": "Mozilla/5.0 ..."
  }
}
  • accessToken is the ChatGPT web access token from your browser session. It is not an official OpenAI API key.
  • cookies and headers should come from the same account/session as the token.
  • .env is optional, not required. If present, accessToken=... is used only as a fallback when the file token is missing or expired.
  • Older files that still use api_key are accepted for backward compatibility, but new examples and new files should use accessToken.
  • If you need to generate this file, capture it with webchat-openai-cli and then reuse it here.

Common Workflows

Streaming Callback

from chatgpt_web_adapter import ChatGPTWebClient

client = ChatGPTWebClient(auth_file="auth_data.json")

response = client.send(
    "Stream the answer token by token.",
    on_token=lambda token: print(token, end="", flush=True),
)

Continue an Existing ChatGPT Web Conversation

from chatgpt_web_adapter import ChatGPTWebClient

client = ChatGPTWebClient(auth_file="auth_data.json")

response = client.send_to_conversation(
    "https://chatgpt.com/c/...",
    "Continue from this point.",
)

print(response.text)

send_to_conversation() attaches to the latest web conversation state, resolves the current parent message automatically, and preserves the detected model when possible. Model detection is best-effort because ChatGPT web payloads can change. If the model cannot be detected, the SDK uses the normal send() default model.

Continue from an SDK Response

from chatgpt_web_adapter import ChatGPTWebClient

client = ChatGPTWebClient(auth_file="auth_data.json")

first = client.send("Start a conversation.")
second = client.send(
    "Continue it.",
    conversation=first.conversation,
)

Other common APIs:

  • read conversation messages with client.get_messages(...)
  • poll conversation status with client.get_status(...)
  • wait for completion with client.wait_until_completed(...)
  • approve selected tool flows with experimental client.send_and_auto_approve(...)
  • inspect request latency with examples/diagnose_latency.py

Examples

Experimental Features

The SDK includes experimental browserless helpers for web-agent/tool approval flows:

  • approve_pending_action()
  • wait_and_approve_pending_actions()
  • send_and_auto_approve()

These APIs are useful for ChatGPT web connector flows such as GitHub file creation, but they rely on reverse-engineered web behavior and should be treated as less stable than the base send() API.

Approval helpers are not a stable contract of this SDK. They are best-effort compatibility layers over changing ChatGPT web approval behavior and may require updates even when the base send/continue flows still work.

See USAGE.md and examples/github_auto_approve.py.

The SDK also includes an experimental raw payload escape hatch for advanced users:

  • PayloadBuilder
  • validate_payload()
  • send_payload()

See docs/raw_payload.md.

This API sends raw ChatGPT web backend payloads. It is not an official or stable API.

The example script includes:

  • a neutral repository placeholder instead of a hard-coded demo repo
  • live assistant token printing
  • structured approval progress events

Auth Notes

This repository only consumes existing auth data. If you still need browser-based capture, generate auth_data.json with webchat-openai-cli first and then reuse it here.

Detailed Guide

For the full SDK walkthrough, including auth flows, warmup(), temporary, web_search, reasoning_effort, conversation continuation, image inputs, response objects, and error handling, see USAGE.md.

Operational docs:

Package Naming

Canonical package naming is:

  • repository: chatgpt-web-adapter
  • distribution: chatgpt-web-adapter
  • import: chatgpt_web_adapter

See docs/rename_compatibility.md.

Status

Initial SDK baseline. The repository is intentionally small and focused on the transport layer first. GitHub Actions validates tests on Python 3.10-3.13 across Ubuntu and Windows, and also checks that the package builds successfully.

Repository docs:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatgpt_web_adapter-0.1.4.tar.gz (84.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chatgpt_web_adapter-0.1.4-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

Details for the file chatgpt_web_adapter-0.1.4.tar.gz.

File metadata

  • Download URL: chatgpt_web_adapter-0.1.4.tar.gz
  • Upload date:
  • Size: 84.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chatgpt_web_adapter-0.1.4.tar.gz
Algorithm Hash digest
SHA256 791608267e15f44dc6af3746faf453383778c053fef043c139aafe7a2a1cbcdd
MD5 31df5a3dfef3f5c36e6831ec93e7fa88
BLAKE2b-256 70d380e4744a03394fc4ee338a16928699d73b44072e1518b4052f9cce2007ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatgpt_web_adapter-0.1.4.tar.gz:

Publisher: publish.yml on kymuco/chatgpt-web-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatgpt_web_adapter-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for chatgpt_web_adapter-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ea204ec3089115c76f193fea9f0fb6288dc51f10deab88ea7ff2f3932f97fe1c
MD5 15a87977683cac5204131f9d2672884d
BLAKE2b-256 3af9f21e2b08441021d15c57e406978740770a1e68ddeeb8eb051bba21dbd82a

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatgpt_web_adapter-0.1.4-py3-none-any.whl:

Publisher: publish.yml on kymuco/chatgpt-web-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page