TypeScript SDK for Scrawn — the open-source usage-based billing engine. Track events, define pricing expressions, bill AI token usage, collect payments, and verify webhooks — all through a single type-safe client.
npm install @scrawn/core @scrawn/analyticsimport { scrawn, mul } from "@scrawn/core";
const biller = scrawn({
apiKey: process.env.SCRAWN_KEY,
baseURL: process.env.SCRAWN_BASE_URL,
httpUrl: process.env.SCRAWN_HTTP_URL,
});
// Track a billable event — 250 cents flat rate
await biller.basicUsageEventConsumer({
userId: "user-123",
debit: 250,
});
// Or with pricing expressions: (API_CALL × 3) + 250
await biller.basicUsageEventConsumer({
userId: "user-123",
debit: biller.expr(add(mul(biller.tag("API_CALL"), 3), 250)),
});See the examples/ directory for complete usage:
basic-usage.ts— flat-rate and tag-based billingbasic-usage-expr.ts— pricing expressions and persistent expressionsai-sdk-wrapper-usage.ts— AI token tracking with any AI SDKai-token-stream-usage.ts— streaming token usagemiddleware-usage.ts— Express/Fastify middlewareanalytics-usage.ts— analytics queries
Full documentation at docs.scrawn.dev