API reference
Core API
The headless engine. Every function takes an optional TokenStore; the default is an encrypted file store.
imports
Functions
login()— loopback OAuth flow (desktop/local), stores tokens.startDeviceLogin()— device-code flow for web/headless; returns{ userCode, verificationUrl, wait }.startLogin()— headless paste flow for SSH/CI; returns{ url, complete }.getSession()— current session, or null.refresh()— force a token refresh.logout()— clear stored tokens.createClient()— a client withrespond(prompt)andstream(prompt).
Login flows
1. Loopback (desktop / CLI)
Auto-opens the browser and catches the redirect on localhost:1455. No user copy-paste needed. Use this for Electron apps, local CLIs, and local-first Next.js dev tools.
login() — loopback
2. Device code (web / Next.js / Docker)
Shows a short code the user enters at an OpenAI page. Works on any server or container — no localhost redirect needed. This is what the playground on this site uses. Requires enabling device code login: ChatGPT → Settings → Security & Login → Allow device code login.
startDeviceLogin() — device code
3. Headless paste (SSH / CI)
Prints the auth URL for the user to open in any browser on any machine, then waits for them to paste the redirect URL back. Pure fallback — use this when there is no browser at all, e.g. an SSH session or a CI pipeline.
startLogin() — headless paste
Models
These models work with the ChatGPT subscription backend. They are not the same as direct OpenAI API models — they only work when the user is signed in with a ChatGPT Plus or Pro account.
| Model | Description | Plan |
|---|---|---|
| gpt-5.5 | Newest frontier model. Best for complex coding. (default) | Plus / Pro |
| gpt-5.4 | Flagship. Strong coding, reasoning, tool use. | Plus / Pro |
| gpt-5.4-mini | Faster, lighter. Good for quick tasks and subagents. | Plus / Pro |
| gpt-5.3-codex-spark | Near-instant coding iteration. Research preview. | Pro only |
pick a model
Token storage
Tokens are encrypted at rest (AES-256-GCM) with a key kept in the OS keychain where available. Storage is pluggable through the TokenStore interface.
custom store
Entry points
loginwithchatgpt— engine (Node).loginwithchatgpt/react— button + hook (browser).loginwithchatgpt/next— App Router handlers (Node).
Back to the Quickstart.