Introduction
Open-source usage-based billing. Track AI tokens, API calls, and complex pricing in one function call. Self-hosted billing infrastructure for developers.
Scrawn - Usage-based billing in one-ish line
Scrawn is the open-source usage engine for developers who need to charge for usage - API calls, AI tokens, storage, database writes, whatever. One SDK call tracks the event, evaluates your pricing, and hands you a payment link. No billing platform to build.
Dodo Gets the Cash. We Do the Math.
We aggregate usage, evaluate your pricing logic, and hand you a payment link in a single function call. You keep full control of your Dodo Payments account.
What is Scrawn?
Scrawn is the missing aggregation layer for DodoPayments. Instead of wiring up gRPC, PostgreSQL, idempotency keys, auth hashing, and pricing resolvers yourself, you call a single SDK function:
import { scrawn } 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
await biller.basicUsageEventConsumer({
userId: "user-123",
debit: 250,
});
const billingLink = await biller.collectPayment("user-123");One function call - no proto files, no DB migrations, no webhook nightmares.
Why Scrawn?
DodoPayments Native
We hook into your existing Dodo account. They handle checkout, tax, and PCI compliance. We handle the metering and pricing logic.
First Class Integrations
Wrap the Vercel AI SDK and auto-bill every LLM call - tokens counted server-side.
Pricing DSL
Express complex pricing with a type-safe DSL - no config files, no spreadsheets.
Self-Hosted & Open Source
Full control over your billing data. PostgreSQL for events, ClickHouse for telemetry. No vendor lock-in. MIT licensed.
Use Cases
- AI/LLM Services - bill per token per model with automatic Vercel AI SDK integration
- API Platforms - charge per request with tag-based pricing tiers
- SaaS Products - usage-based pricing for any metric
- Dev Tools - metered access to CLI tools or build pipelines
Features
- DodoPayments Native - we plug into your existing Dodo account; no Stripe migration needed
- AI Token Metering - first-class support for Vercel AI SDK (
streamText,generateText,streamObject,generateObject) - Pricing DSL -
mul(),add(),sub(),tag()- type-safe expressions for any pricing model - Middleware Mode - intercept requests, extract user IDs and costs, bill automatically
- Self-Hosted - your DB, your data, your infra. Docker compose included.
- gRPC Backend - high-performance, stateless, horizontally scalable
- Type-Safe SDK - full TypeScript types for events, errors, and configuration
- Framework Agnostic - Express, Fastify, Hono, Next.js, tRPC, NestJS - any Node.js HTTP framework
Getting Started
Quick Start
Get running in under 5 minutes - clone, configure, deploy, install, bill.
SDK Reference
Functions, pricing DSL, production patterns, and framework integration.
Usage Tracking
Track billable events manually or drop in the middleware.
Open Source
Scrawn is MIT licensed and available on GitHub. Star us, contribute, or fork it - it's yours.