Function: init()
Prefactor TypeScript SDK / @prefactor/packages/ai / init
Function: init()
Section titled “Function: init()”init(
config?,middlewareConfig?):LanguageModelV3Middleware
Defined in: packages/ai/src/init.ts:144
Initialize the Prefactor AI middleware and return it for use with wrapLanguageModel.
This is the main entry point for the SDK. Call this function to create a middleware instance that you can pass to the Vercel AI SDK’s wrapLanguageModel function.
Parameters
Section titled “Parameters”config?
Section titled “config?”Partial<{ }>
Optional configuration object for transport settings
middlewareConfig?
Section titled “middlewareConfig?”Optional middleware-specific configuration
Returns
Section titled “Returns”LanguageModelV3Middleware
Middleware object to use with wrapLanguageModel
Examples
Section titled “Examples”import { init, shutdown } from '@prefactor/ai';import { generateText, wrapLanguageModel } from 'ai';import { anthropic } from '@ai-sdk/anthropic';
// Initialize with HTTP transport configconst middleware = init({ transportType: 'http', httpConfig: { apiUrl: 'https://app.prefactorai.com', apiToken: process.env.PREFACTOR_API_TOKEN!, agentIdentifier: '1.0.0', },});
// Wrap your model with the middlewareconst model = wrapLanguageModel({ model: anthropic('claude-3-haiku-20240307'), middleware,});
const result = await generateText({ model, prompt: 'Hello!',});
await shutdown();const middleware = init({ transportType: 'http', httpConfig: { apiUrl: 'https://app.prefactorai.com', apiToken: process.env.PREFACTOR_API_TOKEN!, agentId: process.env.PREFACTOR_AGENT_ID, agentIdentifier: '1.0.0', },});const middleware = init( { transportType: 'http', httpConfig: { apiUrl: 'https://app.prefactorai.com', apiToken: process.env.PREFACTOR_API_TOKEN!, agentIdentifier: '1.0.0', }, }, { captureContent: false } // Don't capture prompts/responses);