Skip to content

SDK overview

Looking for refunds via the new agent SDK (@q3labs/pact-sdk)? See Agent SDK → Overview. That’s a different product — this page covers pact-monitor-sdk, the recording-only library.

pact-monitor-sdk is a thin fetch() wrapper that records every call’s outcome. Drop it in where you’d use fetch().

  • Refunds with zero work → use Market (host swap).
  • Can’t route through Market (contractual relationship, call must come from your IP) → use the SDK.
  • Contribute reliability data without enabling refunds → SDK with default config. No API key needed for local-only recording.
Terminal window
npm install @pact-network/monitor
# or
pnpm add @pact-network/monitor
# or
yarn add @pact-network/monitor

Requires Node.js 18+ (uses the built-in global fetch).

import { pactMonitor } from '@pact-network/monitor';
const monitor = pactMonitor(); // local only, no key required
const res = await monitor.fetch('https://upstream.example/v1/<path>', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'getBalance',
params: ['...'],
}),
});

That’s the whole basic API. monitor.fetch() signature matches fetch().

ModeConfigAPI key?What you get
Local onlypactMonitor()NoLocal recording, getStats(), getRecords().
Sync to backendpactMonitor({ syncEnabled: true, apiKey: '...' })YesLocal + records posted to the backend; contributes to the public reliability index.

The monitor never breaks the upstream call. Recording and sync are wrapped in try/catch; don’t add error handling that re-throws on monitor failures. If the SDK ever breaks an upstream call, file a bug.