Skip to main content
The Precipiq TypeScript SDK is the official client library for the AI Consequences Ledger. It has zero runtime dependencies beyond the host’s native fetch, ships ESM and CJS side by side, and is fully tree-shakeable.

Install

The SDK runs on Node 18+, Bun, and Deno. It also works in modern browsers when bundled with type declarations.

Constructor

new Precipiq(apiKey, options?)

With raiseOnError: false (the default), failed requests fall through to onError instead of throwing. Install the SDK on a hot request path without fear of a Precipiq outage crashing your app.

Methods

logDecision(params)Promise<DecisionReceipt | null>

Queues a decision for a batched ship (default) or POSTs it immediately when enableBatching: false. Returns null when batching is enabled because the decision is queued; returns a DecisionReceipt when enableBatching: false.

flush()Promise<void>

Drain the in-memory buffer immediately. Call this during graceful shutdown to ensure no decisions are lost.

linkOutcome(decisionId, financialEventId, options)Promise<LinkReceipt | null>

Link a previously logged decision to a financial event.

getAiPnl(range, agentId?)Promise<AIPnLResponse | null>

Fetch the aggregated AI P&L for the authenticated org. Returns null when the request fails and raiseOnError is false.

track(agentId, actionType, handler) → wrapped handler

Wraps an async function so that every call automatically produces a decision record. The arguments become inputs and the return value becomes outputs.

Types

All core types are re-exported from the package root so you can import them directly from 'precipiq':

Errors

Errors are only thrown when raiseOnError: true. With the default raiseOnError: false, failures are routed to the onError callback and swallowed.

Adapters

LangChain adapter

Automatically track every LLM, tool, and chain call in a LangChain application.

CrewAI adapter

Track every agent task execution in a CrewAI workflow via the step_callback hook.