> ## 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 lets you charge customers for what they actually use—API calls, storage, AI tokens, or any metric you define. Customers pay for consumption, not fixed fees.

<Info>
  **Perfect 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}
    {
      "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 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

### Meters

Meters aggregate events into billable quantities:

* **Count**: Total events (API calls)
* **Sum**: Add values (total bytes)
* **Max**: Highest value (peak users)
* **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="Create meter interface" 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="Pricing configuration" style={{ maxHeight: '500px', width: 'auto' }} width="732" height="712" data-path="images/usage-based/UBB-4.png" />
</Frame>

**Example**: 2,500 calls - 1,000 free = 1,500 × $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">
    In your dashboard: **Meters** → **Create Meter**

    1. Set event name (e.g., `api.call`)
    2. Choose aggregation (Count, Sum, Max, Last)
    3. Add optional filters
  </Step>

  <Step title="Add to Product">
    Link meter to a product with 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 meter to product" style={{ maxHeight: '500px', width: 'auto' }} width="2272" height="1422" data-path="images/usage-based/UBB-5.png" />
    </Frame>

    1. Select **Usage-Based Billing**
    2. Choose your meter
    3. Set price per unit and 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" style={{ maxHeight: '500px', width: 'auto' }} width="1602" height="888" data-path="images/guides/usage-based-billing/meter-quantities-chart.png" />
    </Frame>

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

## Use Cases

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

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

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

  <Card title="Communication" icon="message">
    Count messages, minutes, 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>
