Skip to main content

Experimental subject-scoped ChatGPT OAuth and subscription transport

Project description

chatgpt-oauth

Experimental, unofficial OAuth and subscription transport for Python apps whose users bring their own ChatGPT account.

Warning This package uses the Codex CLI's public OAuth client and an undocumented ChatGPT backend API. It is not an official OpenAI SDK. Treat refresh tokens like passwords, never pool credentials between users, and keep an API-key or local-model fallback.

Every credential operation requires a nonempty subject derived from your application's trusted session. JWT account_id, plan_type, and email claims are unverified routing/display metadata and never application identity.

pip install chatgpt-oauth
import asyncio
from pathlib import Path

import httpx

from chatgpt_oauth import (
    AuthSession,
    ResponseRequest,
    create_client,
    create_file_store,
    login_with_loopback,
)


async def main() -> None:
    subject = "local-user"  # explicit app-owned identity; never ambient
    store = await create_file_store(Path.home() / ".my-app" / "chatgpt")
    async with httpx.AsyncClient() as client:
        auth = AuthSession(store=store, client=client)
        await login_with_loopback(auth, subject)
        ai = create_client(auth, subject, client=client)
        result = await ai.respond(
            ResponseRequest(model="gpt-5.4-mini", input="Explain CAS in one sentence.")
        )
        print(result.output_text)


asyncio.run(main())

login_with_loopback composes begin_login → print (or open=) the authorize URL → wait_for_loopback_callbackcomplete_login. Passing one shared httpx.AsyncClient to both AuthSession and create_client keeps the example to a single async with — neither object owns (or closes) a client it didn't create, so nothing leaks.

The file store creates a 0700 directory, a 0600 AES-256-GCM key, and an atomically replaced 0600 encrypted credential file. Set CHATGPT_OAUTH_KEY to base64, base64url, or 64-character hex encoding exactly 32 bytes to manage the key externally.

Failures inherit ChatGPTOAuthError and expose a stable code: StateMismatchError, ReauthRequired, TokenRefreshError, RateLimitError, AuthError, TransportError, DisabledError, and StoreError.

MIT

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_oauth-0.1.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

chatgpt_oauth-0.1.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file chatgpt_oauth-0.1.0.tar.gz.

File metadata

  • Download URL: chatgpt_oauth-0.1.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for chatgpt_oauth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b729fca7714d95d7c0d13bf8d0a0b790e6ecaefb974b7cbf325e678a7df348e
MD5 f88b01ddc03994aa20fd350cf1baff8b
BLAKE2b-256 66d9989aa3746964681c3610669fc92ee7d16bd08673acc4f02a20956c0e969f

See more details on using hashes here.

File details

Details for the file chatgpt_oauth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chatgpt_oauth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for chatgpt_oauth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60e8baa5cb938bdc5bf4cb245baf6992bc0c6ae416f9200a8e1c865fb460cf22
MD5 cdacb5744f7b6840d79c147da978db95
BLAKE2b-256 c39c606f510108643bd069cabb7efb882ec41c5db36be8c3752d7ab9985c4def

See more details on using hashes here.

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