FlightRecorder
FlightRecorder is the main API surface of @ai-flight-recorder/sdk. It wraps the lower-level Recorder from core and adds plugins, transports, and provider adapter support.
Creating an instance
Section titled “Creating an instance”import { FlightRecorder } from "@ai-flight-recorder/sdk";
const fr = new FlightRecorder();Pass options at construction time:
import { FlightRecorder, ConsoleLogPlugin, InMemoryTransport } from "@ai-flight-recorder/sdk";
const fr = new FlightRecorder({ plugins: [new ConsoleLogPlugin()], transport: new InMemoryTransport(),});Session lifecycle
Section titled “Session lifecycle”// Start a session — throws if one is already activefr.startSession({ label: "chat" });
// Record events manuallyfr.record({ type: "prompt", model: "gpt-4o", prompt: "Hello" });fr.record({ type: "completion", response: "Hi!", finishReason: "stop", totalTokens: 12 });
// End the session — calls transport.save() automaticallyconst session = fr.endSession();label is optional but appears in the DevTools session list and .flight exports.
Using adapters
Section titled “Using adapters”Rather than calling fr.record() manually, use a provider adapter to intercept every call automatically:
import OpenAI from "openai";import { FlightRecorder, wrapOpenAI } from "@ai-flight-recorder/sdk";
const fr = new FlightRecorder();const openai = wrapOpenAI(new OpenAI(), fr.recorder);
fr.startSession({ label: "chat" });await openai.chat.completions.create({ model: "gpt-4o", messages: [...] });fr.endSession();See Adapters for OpenAI, Anthropic, and Gemini wrappers.
Plugins
Section titled “Plugins”Attach plugins with .use() — it’s chainable and checks for duplicate names at registration:
fr.use(pluginA).use(pluginB);See Plugins for details.
Transports
Section titled “Transports”transport.save() is called automatically when endSession() runs. Pass a transport at construction or use the default in-memory store.
See Transports for details.
Accessing the underlying recorder
Section titled “Accessing the underlying recorder”If you need direct access to the core Recorder (e.g. to pass to an adapter):
const recorder = fr.recorder;