Skip to content

ScrawnDotDev/Scrawn.js

@scrawn/core

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.

Installation

npm install @scrawn/core @scrawn/analytics

Quick start

import { 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)),
});

Examples

See the examples/ directory for complete usage:

Docs

Full documentation at docs.scrawn.dev

About

TypeScript SDK for Scrawn billing: events, pricing expressions, AI tokens, webhooks

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages