Quickstart

From install to working in two files

For a local-first Next.js (App Router) app. react is an optional peer dependency you only need for the button.

1. Install

Install

bun add loginwithchatgpt

2. Mount the route handlers

One catch-all route serves /api/chatgpt/login, /session, and /logout.

route handlers

// app/api/chatgpt/[...lwc]/route.ts
import { createHandlers } from "loginwithchatgpt/next";

export const runtime = "nodejs";
export const { GET, POST } = createHandlers();

3. Drop in the button

the button

"use client";
import { LoginWithChatGPT } from "loginwithchatgpt/react";

export default function Page() {
  return <LoginWithChatGPT onConnected={(s) => console.log(s.account.email)} />;
}

4. Make AI calls

Once a user is connected, calls bill their subscription. No API key anywhere.

an AI call

// app/api/chat/route.ts
import { createClient } from "loginwithchatgpt";

export const runtime = "nodejs";

export async function POST(req: Request) {
  const { prompt } = await req.json();
  const text = await createClient().respond(prompt);
  return Response.json({ text });
}

Next step

See the full API reference for the core functions, login flows, and token storage.