Login with ChatGPT
Guides

Production checklist

Everything to set, review, and verify before real users sign in.

Local defaults are forgiving on purpose: an ephemeral secret, an in-memory store, no model restrictions. Production needs deliberate choices. Work down this list.

Required

Set a stable secret from your host's environment manager. Without one the SDK generates an ephemeral secret per boot, and every restart logs everyone out. Rotating the secret does the same, so plan rotations.

.env
LWC_SECRET="$(openssl rand -hex 32)"

Use a shared sessionStore. The default MemoryStore loses sessions on restart and does not work across serverless invocations, containers, or preview deployments. Back it with Redis or a database; the interface is three methods.

Keep consent intact. Ship the default widget's consent step, or equivalent informed consent before login() in custom UIs (why).

Use HTTPS, and confirm your reverse proxy forwards X-Forwarded-Proto so the session cookie gets Secure (details).

Proxy guardrails

  • Set responsesProxy.allowedModels to the models your product actually offers.
  • Review the default rate limit (30 requests/minute per session) for your product. Pass a shared rateLimit.store when running multiple instances, because the default counter is per instance.
  • Keep responsesProxy.maxRequestBytes (40 MiB default) in line with the attachments you accept, and cap prompt size and attachment types at your app boundary.
  • Add an operator kill switch in front of /responses for abuse emergencies.
  • If you need custom quotas or audit logging, wrap auth.proxyFetch(request) in your own route so raw tokens still stay inside the handler.
server.ts
const auth = createChatGPTHandler({
  secret: process.env.LWC_SECRET,
  sessionStore: redisStore,
  responsesProxy: {
    allowedModels: ["gpt-5.5", "gpt-5.4-mini"],
    rateLimit: { limit: 20, windowMs: 60_000, store: redisRateLimitStore },
  },
});

Topology

Same-origin apps can leave allowedOrigins unset and keep the default SameSite=Lax cookie. A split frontend and backend needs the cross-origin guide: allowedOrigins, SameSite=None, credentialed fetches, and your own CORS headers.

Leave dangerouslyAllowTokenExport off for normal web apps. Only enable it when your application server intentionally accepts custody of raw ChatGPT bearer tokens, and never forward refresh-token export output anywhere.

Operations

  • Give users a visible sign-out that hits /logout, and delete sessions server-side when they close their account.
  • Log /responses metadata (session id, model, status, duration) for abuse review. Do not log prompts or attachments.
  • Smoke-test after every deploy and dependency upgrade: login, GET /models returns slugs, one streaming response completes.
  • Review OpenAI terms and policy for your use case before launch.

On this page