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.
- Source: prefactordev/typescript-sdk
- DeepWiki: prefactordev/typescript-sdk on DeepWiki
Choose a package
Section titled “Choose a package”| Package | Use it when | Reference |
|---|---|---|
@prefactor/core | You want the core runtime, manual spans, or your own wrapper layer. | Core API |
@prefactor/langchain | You are instrumenting LangChain applications. | LangChain package |
@prefactor/ai | You are instrumenting apps built on the Vercel AI SDK. | AI package |
@prefactor/claude | You are instrumenting Claude-specific agent flows. | Claude package |
@prefactor/openclaw-prefactor-plugin | You are integrating Prefactor into OpenClaw plugin workflows. | OpenClaw plugin |
Installation
Section titled “Installation”Install the package you need:
npm install @prefactor/langchainOr install a different package:
npm install @prefactor/corenpm install @prefactor/langchainnpm install @prefactor/ainpm install @prefactor/claudenpm install @prefactor/openclaw-prefactor-pluginQuick start
Section titled “Quick start”The SDK exposes three entry points. init from an integration package (such as @prefactor/langchain) returns middleware directly and is the right choice for most applications. init from @prefactor/core with a provider argument returns a PrefactorClient with access to getMiddleware(), getTracer(), and shutdown(). createCore from @prefactor/core is for manual instrumentation without a provider. Use the integration package init unless you need programmatic client access or custom spans.
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 prefer the full options surface — providers, transports, and manual span control — use init from @prefactor/core directly. See the API overview for examples.
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!, },});