Overview
SDK reference for Scrawn — functions, pricing DSL, and production patterns
Everything you need to integrate Scrawn into your application.
Configuration
scrawn() is the factory that creates your billing instance:
import { scrawn, tag } from "@scrawn/core";
const biller = scrawn({
apiKey: process.env.SCRAWN_KEY as `scrn_${string}`,
baseURL: process.env.SCRAWN_BASE_URL || "http://localhost:8069",
tags: ["PREMIUM_CALL", "EXTRA_FEE"] as const,
expressions: ["MY_EXPR"] as const,
retryCount: 3,
});The factory accepts a single config object:
| Param | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | Your Scrawn API key (starts with scrn_) |
baseURL | string | — | Base URL of your Scrawn backend (e.g. http://localhost:8069) |
secure | boolean | true | Whether to use TLS for gRPC. Set to false for local dev |
tags | readonly string[] | — | Known tag names for compile-time type checking on biller.tag() |
expressions | readonly string[] | — | Known expression names for compile-time type checking on biller.expr() |
retryCount | number | 2 | Auto-retry attempts on transient network errors. Set to 0 to disable |
Functions
The core methods you call in your code to track usage, bill AI tokens, and collect payments.
Usage Tracking
Track billable events — manually with basicUsageEventConsumer() or automatically with middlewareEventConsumer().
AI Token Billing
Meter AI token usage per-call with aiTokenStreamConsumer(), biller.ai(), or trackAI().
Collect Payments
Generate a Dodo checkout link when a user's balance crosses your threshold.
Reference & Guides
Pricing expressions, production patterns, and framework integration.
Pricing DSL
Type-safe expressions for complex pricing — mul(), add(), tag(), inputTokens(), and more.
Production Patterns
Error handling, retries, batch processing, caching, and environment configuration.
Framework Recipes
Quick integration patterns for Express, Next.js, Fastify, NestJS, tRPC, Hono, and Nuxt.