Skip to content

Getting started with the TypeScript SDK

The TypeScript SDK is split into a core runtime and integration packages. Start with the package that matches the app you are instrumenting.

PackageUse it whenReference
@prefactor/coreYou want the core runtime, manual spans, or your own wrapper layer.Core API
@prefactor/langchainYou are instrumenting LangChain applications.LangChain package
@prefactor/aiYou are instrumenting apps built on the Vercel AI SDK.AI package
@prefactor/claudeYou are instrumenting Claude-specific agent flows.Claude package
@prefactor/openclaw-prefactor-pluginYou are integrating Prefactor into OpenClaw plugin workflows.OpenClaw plugin

Install the package you need:

Terminal window
npm install @prefactor/langchain

Or install a different package:

Terminal window
npm install @prefactor/core
npm install @prefactor/langchain
npm install @prefactor/ai
npm install @prefactor/claude
npm install @prefactor/openclaw-prefactor-plugin

Most applications start with an integration package. This example uses the LangChain package:

import { init as initLangChain } from '@prefactor/langchain';
const middleware = initLangChain({
transportType: 'http',
httpConfig: {
apiUrl: process.env.PREFACTOR_API_URL!,
apiToken: process.env.PREFACTOR_API_TOKEN!,
agentIdentifier: '1.0.0',
},
});

If you want manual instrumentation or your own wrapper layer, start with @prefactor/core:

import { createCore } from '@prefactor/core';
const prefactor = createCore({
transportType: 'http',
httpConfig: {
apiUrl: process.env.PREFACTOR_API_URL!,
apiToken: process.env.PREFACTOR_API_TOKEN!,
},
});