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_callback → complete_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chatgpt_oauth-0.2.0.tar.gz.
File metadata
- Download URL: chatgpt_oauth-0.2.0.tar.gz
- Upload date:
- Size: 67.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8675f8682866961a888efe195f278b3d607a5d82111968f3303aa321ae9424b
|
|
| MD5 |
07696450f634a0ac9c8ea636f6fa826c
|
|
| BLAKE2b-256 |
df81e7b91e4159362d96ffa84f83bd056d04aecd303cdd19719535a49af0f2b8
|
File details
Details for the file chatgpt_oauth-0.2.0-py3-none-any.whl.
File metadata
- Download URL: chatgpt_oauth-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a24d47e443c490552febd6d10ee569a55ecdd9b1395756c98ee0833616ae3423
|
|
| MD5 |
db2a322b0e18985bdbe920068c353875
|
|
| BLAKE2b-256 |
f0cc9b7f8aca52cc99e8f597ebc0232ad82dc257b07c3bef27a1d83b8d49c2e0
|