Skip to main content

Use the OpenAI Python SDK with your own ChatGPT subscription

Project description

login-with-chatgpt

Use the official openai Python package with your own ChatGPT subscription. Authentication follows the OAuth and ChatGPT-backed Codex transport implemented by the reference login-with-chatgpt project.

[!WARNING] This package uses a private, undocumented ChatGPT Codex endpoint. It is not the OpenAI API, has no compatibility or availability guarantee, and may stop working when the upstream protocol changes. Requests consume the signed-in user's own ChatGPT plan.

Install and sign in

uvx login-with-chatgpt login
uv add login-with-chatgpt

Browser PKCE is the default. For SSH, containers, or other headless environments:

uvx login-with-chatgpt login --device

Credentials are stored in the operating system keyring. The SDK never falls back to a plaintext token file.

OpenAI-compatible Responses client

login_with_chatgpt.OpenAI() returns an actual openai.OpenAI instance, so upstream response types, exceptions, parsing, streaming, and tool helpers remain available.

from login_with_chatgpt import OpenAI

client = OpenAI()
response = client.responses.create(
    model="gpt-5.6-sol",
    input="Explain Python descriptors in three sentences.",
)
print(response.output_text)

Async code uses AsyncOpenAI().

Structured output

from pydantic import BaseModel
from login_with_chatgpt import OpenAI


class Answer(BaseModel):
    summary: str
    points: list[str]


client = OpenAI()
response = client.responses.parse(
    model="gpt-5.6-sol",
    input="Summarize OAuth PKCE.",
    text_format=Answer,
)
print(response.output_parsed)

The supported surface is deliberately limited to POST /responses. Use ChatGPTAccount().list_models() or login-with-chatgpt models for model listing.

Guaranteed request features are text, SSE streaming, Pydantic structured output, function tools, image URL/data URL input, function-result continuation, and stateless multi-turn input replay. The SDK does not execute function tools.

Stateful response parameters (previous_response_id, conversation, background mode, and store=True) are rejected. Output token limits are also rejected because the private endpoint does not honor them; the SDK never silently removes a caller-specified usage limit.

Profiles and diagnostics

login-with-chatgpt --profile work login
login-with-chatgpt profiles
login-with-chatgpt use work
login-with-chatgpt status
login-with-chatgpt models
login-with-chatgpt doctor
login-with-chatgpt logout

Profile precedence is: explicit --profile / Python argument, LOGIN_WITH_CHATGPT_PROFILE, active profile, then default.

The Codex protocol version is pinned to the version tested by this package. For an urgent compatibility override, set LOGIN_WITH_CHATGPT_CLIENT_VERSION or pass client_version="0.144.1" to OpenAI(), AsyncOpenAI(), or ChatGPTAccount(). doctor compares the effective protocol version with an installed Codex CLI when one is available; the CLI is not a package dependency.

Development

uv sync --dev
uv run ruff check .
uv run pyright
uv run pytest
uv build

Real-account contract checks are opt-in because they consume subscription usage:

$env:LOGIN_WITH_CHATGPT_LIVE_MODEL = "gpt-5.6-sol"
uv run pytest -m live

On POSIX shells, use export instead of set. Live tests use the currently active credential profile and are never run by CI.

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

login_with_chatgpt-0.1.1.tar.gz (70.2 kB view details)

Uploaded Source

Built Distribution

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

login_with_chatgpt-0.1.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file login_with_chatgpt-0.1.1.tar.gz.

File metadata

  • Download URL: login_with_chatgpt-0.1.1.tar.gz
  • Upload date:
  • Size: 70.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for login_with_chatgpt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bef3371fee17fe78ad076bdff02e8581b5ebde70b00d3597c7a47bf7480f2eb5
MD5 6a6a4de45f516299b0ae591331d7e445
BLAKE2b-256 a4732bc42caa0e57e394e3bb24c83128e81c7aa2eb99258ec04f78814477614c

See more details on using hashes here.

File details

Details for the file login_with_chatgpt-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for login_with_chatgpt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1222be8b205a6736156bd522983781273dfd527118a1b13cf44afb559215dd54
MD5 7865cc8d186284ed3daa561911a4c921
BLAKE2b-256 7a448b62488fdec5a998fb11076809cf4589df60453c8aba9e1e1317c3b5f246

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