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().
When to use the SDK vs Market
Section titled “When to use the SDK vs Market”- 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.
Install
Section titled “Install”npm install @pact-network/monitor# orpnpm add @pact-network/monitor# oryarn add @pact-network/monitorRequires Node.js 18+ (uses the built-in global fetch).
Minimal usage
Section titled “Minimal usage”import { pactMonitor } from '@pact-network/monitor';
const monitor = pactMonitor(); // local only, no key requiredconst 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().
| Mode | Config | API key? | What you get |
|---|---|---|---|
| Local only | pactMonitor() | No | Local recording, getStats(), getRecords(). |
| Sync to backend | pactMonitor({ syncEnabled: true, apiKey: '...' }) | Yes | Local + records posted to the backend; contributes to the public reliability index. |
The golden rule
Section titled “The golden rule”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.
Cross-links
Section titled “Cross-links”- SDK → Reference — full options, methods, return types.
- Classifier & refund policy — how Pact labels calls.
- Quickstart → host swap — Market path (no SDK needed).