Skip to content

SDK reference

For the mental model, see SDK → Overview.

Returns a monitor instance.

function pactMonitor(options?: PactMonitorOptions): PactMonitor;
FieldTypeDefaultNotes
syncEnabledbooleanfalseIf true, records are posted to the backend and contribute to the public reliability index. Requires apiKey.
apiKeystringPact API key. Required when syncEnabled is true.
endpointstringhttps://api.pactnetwork.ioBackend base URL. Override for local testing.
userAgentstringpact-monitor-sdk/<version>Sent on backend sync.

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
});
OptionTypeNotes
usdcAmountnumberOverride 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.

Returns aggregate stats over the records this monitor instance has collected.

const stats = monitor.getStats();
// { totalCalls, successCount, errorCount, ... }

Returns the raw record buffer.

const records = monitor.getRecords();

Use for debugging or to ship records to your own backend.

Flushes any pending sync, closes timers, releases resources. Call on process exit.

process.on('SIGINT', () => {
monitor.shutdown();
process.exit(0);
});

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.