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
Metadata
Release files for chatgpt-oauth 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chatgpt_oauth-0.2.0.tar.gz | 67.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chatgpt_oauth-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.9 kB
Release files / chatgpt_oauth-0.2.0.tar.gz
| Download URL | chatgpt_oauth-0.2.0.tar.gz |
|---|---|
| Size | 67.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8675f8682866961a888efe195f278b3d607a5d82111968f3303aa321ae9424b
|
|
BLAKE2b-256 checksum How to use checksums |
df81e7b91e4159362d96ffa84f83bd056d04aecd303cdd19719535a49af0f2b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / chatgpt_oauth-0.2.0-py3-none-any.whl
| Download URL | chatgpt_oauth-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a24d47e443c490552febd6d10ee569a55ecdd9b1395756c98ee0833616ae3423
|
|
BLAKE2b-256 checksum How to use checksums |
f0cc9b7f8aca52cc99e8f597ebc0232ad82dc257b07c3bef27a1d83b8d49c2e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|