SDK reference
For the mental model, see SDK → Overview.
pactMonitor(options?)
Section titled “pactMonitor(options?)”Returns a monitor instance.
function pactMonitor(options?: PactMonitorOptions): PactMonitor;PactMonitorOptions
Section titled “PactMonitorOptions”| Field | Type | Default | Notes |
|---|---|---|---|
syncEnabled | boolean | false | If true, records are posted to the backend and contribute to the public reliability index. Requires apiKey. |
apiKey | string | — | Pact API key. Required when syncEnabled is true. |
endpoint | string | https://api.pactnetwork.io | Backend base URL. Override for local testing. |
userAgent | string | pact-monitor-sdk/<version> | Sent on backend sync. |
Methods on the returned PactMonitor
Section titled “Methods on the returned PactMonitor”fetch(input, init?, options?)
Section titled “fetch(input, init?, options?)”Drop-in for fetch(). Accepts the same args plus an optional third arg.
const res = await monitor.fetch(url, init, { usdcAmount: 0.001, // manual payment hint when no x402/MPP headers present});| Option | Type | Notes |
|---|---|---|
usdcAmount | number | Override the per-call USDC amount. Pact infers from x402/MPP headers; set this when you know the amount. |
Response-schema validation is flagged as a future option, not in v1.
getStats()
Section titled “getStats()”Returns aggregate stats over the records this monitor instance has collected.
const stats = monitor.getStats();// { totalCalls, successCount, errorCount, ... }getRecords()
Section titled “getRecords()”Returns the raw record buffer.
const records = monitor.getRecords();Use for debugging or to ship records to your own backend.
shutdown()
Section titled “shutdown()”Flushes any pending sync, closes timers, releases resources. Call on process exit.
process.on('SIGINT', () => { monitor.shutdown(); process.exit(0);});Errors
Section titled “Errors”The SDK never throws on internal failures. Errors are caught, logged at
debug (or via the configured logger), and fetch() proceeds. Hook
the logger if you need monitor-failure visibility.