> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream Blueprint

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

## Use Cases

Explore common scenarios supported by the Stream Blueprint:

<CardGroup cols={2}>
  <Card title="Video Platforms" icon="video">
    Bill customers based on video bandwidth consumption and streaming quality.
  </Card>

  <Card title="Music Streaming" icon="music">
    Track audio streaming usage per user for subscription tiers.
  </Card>

  <Card title="Live Events" icon="signal-stream">
    Monitor live stream consumption and charge for bandwidth usage.
  </Card>

  <Card title="Real-Time Data" icon="wave-pulse">
    Track real-time data transfer for IoT and telemetry applications.
  </Card>
</CardGroup>

<Info>
  Perfect for video/audio streaming platforms, live streaming services, and real-time data applications.
</Info>

## Quick Start

Track streaming bytes consumed by your customers:

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    npm install @dodopayments/ingestion-blueprints
    ```
  </Step>

  <Step title="Get Your API Keys">
    * **Dodo Payments API Key**: Get it from [Dodo Payments Dashboard](https://app.dodopayments.com/developer/api-keys)
  </Step>

  <Step title="Create a Meter">
    Create a meter in your [Dodo Payments Dashboard](https://app.dodopayments.com/):

    * **Event Name**: `stream_consumption` (or your preferred name)
    * **Aggregation Type**: `sum` to track total bytes streamed
    * **Over Property**: `bytes` to bill based on bandwidth usage
  </Step>

  <Step title="Track Stream Usage">
    <CodeGroup>
      ```javascript Video Streaming theme={null}
      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 stream consumption
      await trackStreamBytes(ingestion, {
        customerId: 'customer_123',
        bytes: 10485760, // 10MB
        metadata: {
          stream_type: 'video',
        }
      });
      ```
    </CodeGroup>
  </Step>
</Steps>

## Configuration

### Ingestion Configuration

<ParamField path="apiKey" type="string" required>
  Your Dodo Payments API key from the dashboard.
</ParamField>

<ParamField path="environment" type="string" required>
  Environment mode: `test_mode` or `live_mode`.
</ParamField>

<ParamField path="eventName" type="string" required>
  Event name that matches your meter configuration.
</ParamField>

### Track Stream Bytes Options

<ParamField path="customerId" type="string" required>
  The customer ID for billing attribution.
</ParamField>

<ParamField path="bytes" type="number">
  Number of bytes consumed in the stream. Required for bandwidth-based billing.
</ParamField>

<ParamField path="metadata" type="object">
  Optional metadata about the stream like stream type, quality, sessionId, etc.
</ParamField>

## Best Practices

<Tip>
  **Track by Chunk**: For long streams, track consumption in chunks rather than waiting for the entire stream to complete.
</Tip>

<Warning>
  **Accurate Byte Counting**: Ensure byte counts include all overhead (headers, protocol overhead) if billing for total bandwidth.
</Warning>
