npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dodopayments/ingestion-blueprints

v0.5.0

Published

Sophisticated Dodo Payments Ingestion Blueprints

Readme

Ingestion Blueprints

Pre-built solutions to track usage and automate billing for your SaaS. Track LLM tokens, API calls, storage uploads, streaming bandwidth, and compute time with just a few lines of code.

Available Blueprints

  • LLM Tracking - Automatic token usage tracking for OpenAI, Anthropic, Groq, AI SDK, and more
  • API Gateway - Track API calls and implement usage-based API billing
  • Object Storage - Monitor file uploads to S3, GCS, Azure Blob, and other storage services
  • Stream - Track streaming data consumption for video, audio, and live streams
  • Time Range - Bill based on compute time for serverless functions, containers, and VMs

LLM Blueprint

Track LLM token usage automatically for usage-based billing. Works with OpenAI, Anthropic, Groq, AI SDK, Google Gemini, and OpenRouter.

📖 Full Documentation

Example

import { createLLMTracker } from '@dodopayments/ingestion-blueprints';
import { generateText } from 'ai';
import { google } from '@ai-sdk/google';

const llmTracker = createLLMTracker({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'your_meter_event_name'
});

const client = llmTracker.wrap({
  client: { generateText },
  customerId: 'customer_123'
});

const response = await client.generateText({
  model: google('gemini-2.0-flash'),
  prompt: 'Hello!',
  maxOutputTokens: 500
});

console.log(response.text);
console.log(response.usage);
// ✅ Usage automatically tracked to Dodo Payments!

API Gateway Blueprint

Track API calls at the gateway level for usage-based API billing. Perfect for API-as-a-service platforms and multi-tenant SaaS.

📖 Full Documentation

Example

import { Ingestion, trackAPICall } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'api_call'
});

// Track an API call
await trackAPICall(ingestion, {
  customerId: 'customer_123',
  metadata: {
    endpoint: '/api/v1/users',
    method: 'GET',
    status_code: 200,
    response_time_ms: 45
  }
});

Object Storage Blueprint

Track file uploads and storage usage for S3, Google Cloud Storage, Azure Blob, and other object storage services.

📖 Full Documentation

Example

import { Ingestion, trackObjectStorage } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'object_storage_upload'
});

// Track S3 upload
await trackObjectStorage(ingestion, {
  customerId: 'customer_123',
  bytes: 1048576, // 1MB
  metadata: {
    bucket: 'my-bucket',
    key: 'uploads/document.pdf'
  }
});

Stream Blueprint

Track streaming data consumption for video, audio, live streams, and real-time data transfer billing.

📖 Full Documentation

Example

import { Ingestion, trackStreamBytes } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'stream_consumption'
});

// Track video streaming
await trackStreamBytes(ingestion, {
  customerId: 'customer_123',
  bytes: 10485760, // 10MB
  metadata: {
    stream_type: 'video'
  }
});

Time Range Blueprint

Track resource consumption based on elapsed time for serverless functions, containers, VMs, and any time-based billing.

📖 Full Documentation

Example

import { Ingestion, trackTimeRange } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'function_execution'
});

// Track function execution time
const startTime = Date.now();
await yourBusinessLogic();
const durationMs = Date.now() - startTime;

await trackTimeRange(ingestion, {
  customerId: 'customer_123',
  durationMs: durationMs,
  metadata: {
    function_name: 'image-processor',
    memory_mb: 512
  }
});

Try the Examples

All blueprints come with runnable examples you can try immediately.

Setup

  1. Clone and install:

    git clone https://github.com/dodopayments/ingestion-blueprints.git
    cd ingestion-blueprints
    npm install
    npm run build
  2. Set up environment variables in examples/.env:

    DODO_PAYMENTS_API_KEY=your_dodo_key_here
    OPENAI_API_KEY=your_openai_key_here
    ANTHROPIC_API_KEY=your_anthropic_key_here
    GROQ_API_KEY=your_groq_key_here
    GOOGLE_GENERATIVE_AI_API_KEY=your_google_key_here
    OPENROUTER_API_KEY=your_openrouter_api_key_here
  3. Run examples:

    cd examples
    npm install
    
    # LLM examples
    npx tsx ai-sdk-example.ts
    npx tsx openai-example.ts
    npx tsx anthropic-example.ts
    npx tsx groq-example.ts
    npx tsx google-genai-example.ts
    npx tsx openrouter-example.ts
    
    # Other blueprint examples
    npx tsx api-gateway-example.ts
    npx tsx object-storage-example.ts
    npx tsx stream-example.ts
    npx tsx time-range-example.ts

Why Use Ingestion Blueprints?

  • 🚀 Quick Integration - Get started in minutes with pre-built solutions
  • 📊 Accurate Tracking - Automatic usage capture with no manual logging
  • 💰 Usage-Based Billing - Convert usage directly into billing events
  • 🔧 Flexible - Track tokens, bytes, API calls, time, or custom metrics
  • 🎯 Production-Ready - Battle-tested, TypeScript support, minimal overhead
  • 🌐 Universal - Works with a variety of popular providers

Perfect for: SaaS platforms, AI applications, API services, streaming platforms, cloud compute billing.


License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

Security

Please report security vulnerabilities to [email protected]. See our Security Policy for more information.

Support