Install the precipiq npm package, configure the constructor, call logDecision and linkOutcome, and handle errors in Node, Bun, or Deno projects.
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.
import { Precipiq } from 'precipiq';const pq = new Precipiq('pq_test_demo_key_REPLACE_ME', { baseUrl: 'https://api.precipiq.dev', // override for self-hosted flushThreshold: 50, // queued items before forced flush flushIntervalSeconds: 5, // background-flush cadence enableBatching: true, // false => ship synchronously raiseOnError: false, // true => throw on API failures timeoutMs: 10_000, // per-request timeout onError: (err) => console.warn(err), // fallback handler});
Option
Type
Description
baseUrl
string
Override the default API root for self-hosted deployments.
flushThreshold
number
Number of queued decisions that trigger a forced flush. Default: 50.
flushIntervalSeconds
number
Seconds between background flushes. Default: 5.
enableBatching
boolean
When false, every logDecision ships immediately and returns a receipt. Default: true.
raiseOnError
boolean
When true, API failures throw instead of routing to onError. Default: false.
timeoutMs
number
Per-request timeout in milliseconds. Default: 10000.
onError
(err: Error) => void
Callback invoked when a request fails and raiseOnError is false.
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.
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.