bytes adds up each customer’s bandwidth, so you can bill for it. The blueprint ships in the @dodopayments/ingestion-blueprints npm package as trackStreamBytes().
Use Cases
The Stream Blueprint fits these scenarios:Video Platforms
Music Streaming
Live Events
Real-Time Data
Use it for video and audio streaming platforms, live streaming services, and real-time data applications.
Quick Start
To track streaming usage, install the package, create a meter, and send the bytes each customer consumes.1
Install the SDK
Install the Dodo Payments Ingestion Blueprints package:
2
Get Your API Keys
Create a Dodo Payments API key under Developer → API Keys in the Dodo Payments dashboard, and store it in the
DODO_PAYMENTS_API_KEY environment variable. Use a test mode key while you build. A test mode key works only with test_mode.3
Create a Meter
In the Dodo Payments dashboard, go to Products → Meters and click Create Meter. Set these fields:
- Meter Name: a descriptive name, such as
Stream Bandwidth. - Event Name:
stream_consumption, or a name you choose. It must matcheventNamein your code exactly (case-sensitive). - Aggregation Type: Sum, to add up the bytes streamed.
- Over Property:
bytes, to bill by bandwidth usage. - Measurement Unit: the unit shown on invoices, such as
bytes.
4
Track Stream Usage
Call
trackStreamBytes() with the customer and the number of bytes consumed:Configuration
Ingestion Configuration
Pass these options tonew Ingestion():
string
required
Your Dodo Payments API key from the dashboard.
string
Environment mode:
test_mode or live_mode. Defaults to test_mode. The Dodo Payments SDKs default to live_mode instead, so set live_mode explicitly in production.string
required
Event name that matches your meter’s Event Name (case-sensitive).
Track Stream Bytes Options
Pass these options totrackStreamBytes():
string
required
The Dodo Payments customer ID to bill for the stream, for example
cus_123.number
Number of bytes consumed in the stream. Required for bandwidth-based billing. If you omit it, the event has no
bytes value, but it still counts toward a Count meter.object
Optional metadata about the stream, such as stream type, quality, or session ID. Each value must be a string, number, or boolean.
Best Practices
Each call totrackStreamBytes() sends a separate event, and a Sum meter adds the chunks together.