JavaScript SDK

@pad-ai/sdk is a tiny, dependency-free client for sending profiles, events, and direct sends from your Node, browser, or edge runtime.

Install

pnpm add @pad-ai/sdk
# or: npm i @pad-ai/sdk

Initialize

import { PAD } from '@pad-ai/sdk';

const pad = new PAD({
  apiKey: process.env.PAD_API_KEY!,
  // Optional — defaults to https://pad.thevisualpay.com
  baseUrl: process.env.PAD_BASE_URL,
});

Identify a profile

await pad.profiles.upsert({
  externalId: 'user_42',
  email: 'ada@acme.com',
  traits: { plan: 'pro', signedUpAt: new Date().toISOString() },
});

Track an event

await pad.events.track({
  externalId: 'user_42',
  event: 'checkout.completed',
  properties: { amount: 99, plan: 'pro' },
  idempotencyKey: 'checkout_42_2026_05_20',
});

Send a transactional email

await pad.sends.send({
  templateSlug: 'welcome',
  externalId: 'user_42',
  variables: { firstName: 'Ada', productName: 'Acme' },
});

Record consent

await pad.consents.set({
  externalId: 'user_42',
  channel: 'email',
  category: 'marketing',
  granted: true,
  source: 'preference-center',
});

Use from the browser

Browser usage requires a scoped API key (scope: browser) — server keys must never ship to the client. Create one in Settings → API keys and pass it via your build environment.

Error handling

Every method returns the parsed JSON on 2xx and throws PadError on 4xx/5xx with status, code, and message fields. Retry on 5xx; 4xx is a bug in your call.