SaaS billing
Sell subscriptions, lifetime deals, team seats, usage credits, and premium feature unlocks. Define entitlements once, then check them in your app with a single verify call.
Seller flow
- Create a SaaS product.
- Create plans — for example Free, Pro, Team, and Business.
- Define entitlements per plan, such as
max_projects = 10,max_api_calls = 100000,feature_ai_export = true, andteam_seats = 5. - Install the SDK in your SaaS app.
- The buyer pays in USDC; your app checks the entitlement.
Define plans with @settlekit/saas
Plans carry feature flags (booleans) and numeric limits. Use createPlan to build a validated SaasPlan and UNLIMITED for limits with no ceiling. It returns a Result, so unwrap .value on success.
import { createPlan, UNLIMITED } from "@settlekit/saas";
const pro = createPlan({
productId: "prod_saas",
name: "Pro",
interval: "monthly", // "monthly" | "yearly"
price: { amount: "29.00", currency: "USDC" },
features: { ai_export: true, max_projects: 100 },
seats: 5,
});
const business = createPlan({
productId: "prod_saas",
name: "Business",
interval: "monthly",
price: { amount: "99.00", currency: "USDC" },
features: { ai_export: true, max_projects: UNLIMITED },
seats: 25,
});
if (!pro.ok) throw new Error(pro.error.message);
const proPlan = pro.value; // SaasPlanThe verify SDK (plan §4)
Every kind of access is an Entitlement, so feature gating is one call. EntitlementService.verify resolves the customer's active entitlements and applies the requested feature / credit check, returning { allowed, reason }.
import {
EntitlementService,
InMemoryEntitlementRepository,
} from "@settlekit/entitlements";
const entitlements = new EntitlementService(
new InMemoryEntitlementRepository(),
);
const result = await entitlements.verify({
customerId: user.id,
feature: "ai_export",
});
if (!result.allowed) {
throw new Error(result.reason ?? "upgrade_required");
}The hosted API exposes the same check at POST /v1/entitlements/verify — see the API reference. The SaaS-specific variant lives at POST /v1/saas/entitlements/verify.
Metered features and credits
For credit-based plans, verify a required balance and spend against it.verify accepts requiredCredits; spendCredits deducts and persists the new balance.
// gate: does the customer have at least 10 credits for this product?
const check = await entitlements.verify({
customerId: user.id,
productId: "prod_saas",
requiredCredits: 10,
});
if (check.allowed) {
// deduct 10 credits and persist the new balance
await entitlements.spendCredits(user.id, "prod_saas", 10);
}Grant on purchase
When a buyer purchases a plan, grant the entitlement from the confirmed payment (or from a subscription for recurring access). The features map flows straight into the entitlement so verify can read it.
const entitlement = await entitlements.grantFromPayment({
payment, // confirmed Payment
product: {
id: "prod_saas",
merchantId: "mer_acme",
organizationId: "org_acme",
name: "Acme Pro",
description: "Pro plan",
type: "saas_plan",
status: "active",
deliveryMode: "saas_entitlement",
metadata: {},
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
features: { ai_export: true, max_projects: 100, team_seats: 5 },
});Next
Charge per call instead of per month with Paid APIs (x402), or hand out license keys for offline apps.