← Back

paiment SDK

Server-side SDKs for the paiment API. Register subscribers, report LLM usage, manage plans.

Install

npm install @paiment/sdk

Node.js 18+. Published on npm.

pip install paiment

Python 3.9+.

Setup

Create an API key in Settings → API Keys.

Key formatUsage
tenantId:workspaceId:secretRecommended — workspace is in the key
tenantId:secretPass workspaceId / workspace_id on the client
import { PaimentClient } from '@paiment/sdk';

const paiment = new PaimentClient({
  apiKey: process.env.PAIMENT_API_KEY!,
  // defaults to https://api.paiment.tech
});
from paiment import PaimentClient

client = PaimentClient(api_key="tenantId:workspaceId:secret")
Backend only. Never expose your API key in a browser or mobile app.

Quick start

Most integrations need three hooks:

  1. User subscribes → subscriptions.create
  2. LLM call completes → usage.report
  3. User cancels → subscriptions.end
const sub = await paiment.subscriptions.create({
  userId: 'user_123',
  externalPlanId: 'price_pro',
  planName: 'Pro',    // optional naming hint
  price: 2999,        // cents
  currency: 'USD',
  interval: 'monthly',
});

await paiment.usage.report({
  userId: 'user_123',
  inputTokens: 1250,
  outputTokens: 340,
  provider: 'openai',
  model: 'gpt-4o',
  externalPlanId: 'price_pro',
});

await paiment.subscriptions.end(sub.id);
sub = client.subscriptions.create(
    user_id="user_123",
    external_plan_id="price_pro",
    plan_name="Pro",
    price=2999,
    currency="USD",
    interval="monthly",
)

client.usage.report(
    user_id="user_123",
    input_tokens=1250,
    output_tokens=340,
    provider="openai",
    model="gpt-4o",
    external_plan_id="price_pro",
)

client.subscriptions.end(sub.id)

Billing webhooks

paiment does not receive your payment-processor webhooks. Your server handles checkout and subscription events, then calls the SDK to sync billing state.

// After your billing provider confirms a new subscription
await paiment.subscriptions.create({
  userId: user.id,
  externalPlanId: plan.id,
  planName: 'Pro',
  price: 2999,
  currency: 'USD',
  interval: 'monthly',
  source: 'billing-webhook',
});

API reference

subscriptions

MethodDescription
createNew subscription (+ user if needed)
listList by userId, status
getGet by subscription id
updatePatch price, status, dates
endClose subscription period
cancelEnd immediately

usage

MethodDescription
reportRecord input/output tokens, provider, model
listList usage rows

users

MethodDescription
createShortcut: user + subscription
getBy your external userId
listList users, filter by plan
updatePartial update
deleteDelete user

plans

MethodDescription
create / list / get / update / deletePlan catalog CRUD

Key fields

FieldMeaning
userIdYour identifier for the end-user
externalPlanIdYour plan key (required on plans, subscriptions, users, usage)
planNameOptional display name; naming hint when auto-creating a plan
priceSubscription price in cents — used for revenue
listPriceCentsCatalog list price only (informational)

Errors

ClassStatus
PaimentAuthError401
PaimentNotFoundError404
PaimentValidationError400
PaimentErrorother