Skip to main content

Use Cases

Explore common scenarios supported by the Time Range Blueprint:

Serverless Functions

Bill based on function execution time and memory usage.

Container Runtime

Track container running time for usage-based billing.

Compute Instances

Monitor VM runtime and charge by the minute or hour.

Background Jobs

Track processing time for data exports, reports, and batch jobs.
Perfect for billing based on compute time, function execution duration, container runtime, or any time-based usage.

Quick Start

Track resource usage by time duration:
1

Install the SDK

npm install @dodopayments/ingestion-blueprints
2

Get Your API Keys

3

Create a Meter

Create a meter in your Dodo Payments Dashboard:
  • Event Name: time_range_usage (or your preferred name)
  • Aggregation Type: sum to track total duration
  • Over Property: durationSeconds, durationMinutes, or durationMs
4

Track Time Usage

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();

// Execute your function (example: image processing)
const result = await yourImageProcessingLogic();

const durationMs = Date.now() - startTime;

await trackTimeRange(ingestion, {
  customerId: 'customer_123',
  durationMs: durationMs
});

Configuration

Ingestion Configuration

apiKey
string
required
Your Dodo Payments API key from the dashboard.
environment
string
required
Environment mode: test_mode or live_mode.
eventName
string
required
Event name that matches your meter configuration.

Track Time Range Options

customerId
string
required
The customer ID for billing attribution.
durationMs
number
Duration in milliseconds. Use for sub-second precision.
durationSeconds
number
Duration in seconds. Most common for function execution and short tasks.
durationMinutes
number
Duration in minutes. Useful for longer-running resources like VMs.
metadata
object
Optional metadata about the resource like CPU, memory, region, etc.

Best Practices

Choose the Right Unit: Use milliseconds for short operations, seconds for functions, and minutes for longer-running resources.
Accurate Timing: Use Date.now() or performance.now() for accurate time tracking, especially for serverless functions.
I