Scrawn LogoScrawn Docs
Scrawn LogoScrawn Docs
Scrawn.js

Overview

Introduction to Scrawn.js SDK

What is Scrawn.js?

Scrawn.js is the official JavaScript/TypeScript SDK for integrating Scrawn's usage-based billing into your applications. It provides a simple, type-safe interface for tracking usage events and collecting payments via gRPC.

Key Features

  • Simple API - Track usage with a single function call
  • Type-Safe - Full TypeScript support with auto-completion
  • gRPC-Powered - Built on Connect-RPC for efficient communication
  • Framework Agnostic - Works with any JavaScript framework
  • Middleware Support - Built-in middleware with whitelist/blacklist patterns

Installation

Install Scrawn.js in your project:

bun add @scrawn/core
npm install @scrawn/core
yarn add @scrawn/core

Quick Example

import { Scrawn } from '@scrawn/core';

const scrawn = new Scrawn({
  apiKey: process.env.SCRAWN_KEY as `scrn_${string}`,
  baseURL: process.env.SCRAWN_BASE_URL || 'http://localhost:8069',
});

// Track a billable event
await scrawn.sdkCallEventConsumer({
  userId: 'user-123',
  debitAmount: 100,
});

Currency Units: Pass the debit amount in whatever currency unit you've configured in your LemonSqueezy dashboard. If you're using dollars, pass dollars directly (e.g., 10.50). The SDK doesn't perform any currency conversion.

Core Methods

sdkCallEventConsumer()

Track usage events programmatically for billing purposes. This is a general-purpose event consumer that can be abstracted for various use cases. View Details.

middlewareEventConsumer()

Automatically track API requests with Express-compatible middleware. Supports whitelist/blacklist patterns with wildcards. View Details.

collectPayment()

Generate a checkout link to collect payment from users. View Details.