> ## 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.

# Usage-Based Billing

> Charge customers based on what they actually use with flexible metering and automated billing.

Usage-based billing charges customers for what they consume—API calls, storage, AI tokens, or any metric you define. Customers pay for what they use. You can add a fixed base fee, or set it to zero.

<Info>
  **Best for**: APIs, AI services, infrastructure platforms, and any product where value scales with usage.
</Info>

## How It Works

<Steps>
  <Step title="Send Usage Events">
    Your application sends events when billable actions occur.

    ```javascript theme={null}
    {
      "events": [
        {
          "event_id": "evt_123",
          "customer_id": "cus_abc",
          "event_name": "api.call",
          "metadata": { "endpoint": "/v1/users" }
        }
      ]
    }
    ```
  </Step>

  <Step title="Meters Aggregate Usage">
    Meters aggregate events into billable quantities using Count, Sum, Max, or Last aggregation.
  </Step>

  <Step title="Automatic Billing">
    Set pricing per unit and optional free thresholds. Customers are billed automatically each cycle.
  </Step>
</Steps>

## Core Concepts

### Events

Events represent usage actions in your application. Each event includes:

* **Event Name**: Type of usage (e.g., `api.call`)
* **Customer ID**: Who used it
* **Metadata**: Additional properties for aggregation and filtering

### Meters

Meters aggregate events into billable quantities:

* **Count**: Total number of events (API calls, uploads)
* **Sum**: Sum of numeric values (total bytes, tokens)
* **Max**: Highest value in the period (peak users, max storage)
* **Last**: Most recent value

<Frame>
  <img src="https://mintcdn.com/dodopayments/w9oVTi6CzZMAOQA3/images/usage-based/UBB-2.png?fit=max&auto=format&n=w9oVTi6CzZMAOQA3&q=85&s=f9d85a463fba231437151db3d4a2052a" alt="Meter creation interface showing event name, aggregation type, and filtering options" style={{ maxHeight: '500px', width: 'auto' }} width="2324" height="1600" data-path="images/usage-based/UBB-2.png" />
</Frame>

### Products with Usage Pricing

Set pricing per unit and optional free thresholds:

<Frame>
  <img src="https://mintcdn.com/dodopayments/w9oVTi6CzZMAOQA3/images/usage-based/UBB-4.png?fit=max&auto=format&n=w9oVTi6CzZMAOQA3&q=85&s=b2d07bb408fd79e1b788c1b7092b8bca" alt="Product pricing configuration for usage-based billing" style={{ maxHeight: '500px', width: 'auto' }} width="732" height="712" data-path="images/usage-based/UBB-4.png" />
</Frame>

**Example**: 2,500 calls minus 1,000 free = 1,500 chargeable calls × \$0.02 = \$30.00

### Credit-Based Deduction

Instead of charging per-unit in dollars, you can configure meters to deduct from a customer's [credit balance](/features/credit-based-billing). Credits refresh each billing cycle and apply before any overage charges.

## Quick Start

<Steps>
  <Step title="Create a Meter">
    Go to **Meters** in the dashboard and click **Create Meter**.

    1. Enter an event name (e.g., `api.call`)
    2. Choose an aggregation type (Count, Sum, Max, or Last)
    3. Add optional filters to exclude certain events
  </Step>

  <Step title="Add Meter to a Product">
    Link the meter to a product and set pricing:

    <Frame>
      <img src="https://mintcdn.com/dodopayments/w9oVTi6CzZMAOQA3/images/usage-based/UBB-5.png?fit=max&auto=format&n=w9oVTi6CzZMAOQA3&q=85&s=fd3851a1a070714baf0aec01cff717b8" alt="Adding a meter to a product with pricing configuration" style={{ maxHeight: '500px', width: 'auto' }} width="2272" height="1422" data-path="images/usage-based/UBB-5.png" />
    </Frame>

    1. Go to **Products** and select or create a product
    2. Select **Usage Based Billing** as the pricing type
    3. Choose your meter
    4. Set the price per unit and optional free threshold
  </Step>

  <Step title="Send Events">
    ```javascript theme={null}
    await fetch('https://test.dodopayments.com/events/ingest', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.DODO_PAYMENTS_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        events: [{
          event_id: "unique_event_id",
          customer_id: "cus_abc123",
          event_name: "api.call",
          metadata: { endpoint: "/v1/users" }
        }]
      })
    });
    ```
  </Step>

  <Step title="Monitor Usage">
    <Frame>
      <img src="https://mintcdn.com/dodopayments/16r81mgDWvSgYER7/images/guides/usage-based-billing/meter-quantities-chart.png?fit=max&auto=format&n=16r81mgDWvSgYER7&q=85&s=1a8a39547bd0259a53d4591d7928c8ea" alt="Meter dashboard showing usage trends over time" style={{ maxHeight: '500px', width: 'auto' }} width="1602" height="888" data-path="images/guides/usage-based-billing/meter-quantities-chart.png" />
    </Frame>

    View your meter's dashboard to see events and aggregated usage. Customers are billed automatically each billing cycle.
  </Step>
</Steps>

## Use Cases

<CardGroup cols={2}>
  <Card title="APIs and Infrastructure" icon="cloud">
    Track API calls, compute hours, bandwidth, or storage. Example: \$0.001 per call after 10,000 free calls.
  </Card>

  <Card title="AI Usage Tracking" icon="brain">
    Track tokens, image generations, or processing time. Example: \$0.04 per standard image, \$0.08 per HD image.
  </Card>

  <Card title="Data and Analytics" icon="chart-line">
    Bill by data processed, queries run, or records analyzed. Example: \$5 per GB after 10 GB free.
  </Card>

  <Card title="Communication" icon="message">
    Count messages, minutes, or data transferred. Example: \$0.01 per SMS sent.
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Event Ingestion" icon="bolt" href="/features/usage-based-billing/event-ingestion">
    Learn how to structure and send usage events from your application.
  </Card>

  <Card title="Meters Guide" icon="sliders" href="/features/usage-based-billing/meters">
    Master meter configuration, aggregation types, and event filtering.
  </Card>

  <Card title="Complete Tutorial" icon="code" href="/developer-resources/usage-based-billing-build-ai-image-generator">
    Build a complete AI image generator with usage-based billing from scratch.
  </Card>

  <Card title="Integration Guide" icon="book" href="/developer-resources/usage-based-billing-guide">
    Comprehensive guide to implementing usage-based billing in your application.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.