Next.js Chat
examples/nextjs-chat is a minimal Next.js 15 app showing a full end-to-end integration: streaming GPT-4o-mini chat, automatic session recording, and .flight export.
cd examples/nextjs-chatcp .env.example .env.localEdit .env.local and add your OpenAI API key:
OPENAI_API_KEY=sk-...pnpm devOpen http://localhost:3000. Chat with the assistant, then click Export .flight in the header to download the session.
Replay in DevTools
Section titled “Replay in DevTools”- Open the DevTools app (
pnpm devfrom the repo root) - Click Import in the toolbar
- Select the
.flightfile
Your session loads instantly with the full timeline, waterfall, cost breakdown, and streaming replay.
How it works
Section titled “How it works”The example wires up three things from the SDK in src/app/api/chat/route.ts:
FlightRecorder— starts a session per requestwrapOpenAI— intercepts the OpenAI client and records every prompt, token, and completion automaticallyserializeSession— serializes the ended session to JSON for download
To switch providers, replace wrapOpenAI with wrapAnthropic or wrapGeminiModel. See Adapters for the cast pattern required by Anthropic and Gemini.