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

# Credit-Based Billing

> Issue, manage, and track credit entitlements across subscriptions, one-time products, and usage-based billing with rollover, overage, and expiration controls.

<Frame>
  <iframe className="w-full aspect-video rounded-md" src="https://www.youtube.com/embed/4RR3Yj3Qeuw" title="Credit-Based Billing Tutorial" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />
</Frame>

<Info>
  Penagihan Berbasis Kredit memungkinkan Anda memberikan pelanggan saldo kredit - panggilan API, token, unit komputasi, atau metrik kustom lainnya - dan menguranginya dari saldo seiring mereka menggunakan layanan Anda. Kredit bekerja di semua jenis produk: langganan, pembelian satu kali, dan penagihan berbasis penggunaan.
</Info>

## Apa itu Penagihan Berbasis Kredit?

Penagihan Berbasis Kredit memberi Anda sistem fleksibel untuk memberikan hak kredit kepada pelanggan sebagai bagian dari produk Anda. Alih-alih menagih per penggunaan atau membatasi akses melalui fitur flags, Anda mengalokasikan sejumlah kredit yang dapat digunakan pelanggan saat mereka menggunakan layanan Anda.

Kredit ideal untuk:

* **Platform AI dan LLM**: Berikan token atau kredit generasi per tingkat rencana
* **Layanan API**: Alokasikan kredit panggilan API dengan harga kelebihan
* **Platform Infrastruktur**: Berikan kredit jam komputasi atau penyimpanan
* **Layanan Komunikasi**: Sediakan kredit pesan atau menit per langganan
* **SaaS dengan tingkat konsumsi**: Gabungkan penggunaan yang termasuk dalam kumpulan kredit

<Frame caption="Credits appear as entitlements on your products and show in checkout, customer portal, and subscription details.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Checkout.png?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=21880df0e4b0b1a3cb8593dbeb8ae343" alt="Checkout menampilkan kredit yang termasuk dengan pembelian produk" style={{ maxHeight: '500px', width: 'auto' }} width="1440" height="960" data-path="images/CBB/Checkout.png" />
</Frame>

## Konsep Inti

### Jenis Kredit

Saat membuat kredit, Anda memilih antara dua jenis:

<Tabs>
  <Tab title="Custom Unit">
    Tentukan kredit dalam unit Anda sendiri - token, panggilan API, jam komputasi, atau metrik apa pun yang bermakna untuk produk Anda. Unit kustom menggunakan presisi yang Anda tetapkan (0 hingga 3 angka desimal).

    **Terbaik untuk**: Panggilan API, token AI, jam komputasi, unit penyimpanan, pesan
  </Tab>

  <Tab title="Fiat Credits">
    Kredit mewakili nilai mata uang sebenarnya (mis., USD, EUR). Pelanggan menerima saldo kredit moneter yang berkurang saat mereka menggunakan layanan Anda pada harga yang Anda tentukan.

    **Terbaik untuk**: Saldo prabayar, kredit promosi, kompensasi layanan
  </Tab>
</Tabs>

### Siklus Hidup Kredit

Kredit mengikuti siklus hidup yang jelas dari penerbitan hingga konsumsi:

<Steps>
  <Step title="Credits Issued">
    Kredit diberikan ketika pelanggan membeli produk (langganan atau satu kali) dengan hak kredit yang terkait. Untuk langganan, kredit diterbitkan kembali setiap siklus penagihan.
  </Step>

  <Step title="Credits Consumed">
    Saat pelanggan menggunakan layanan Anda, kredit dikurangi. Untuk produk berbasis penggunaan, pengukur secara otomatis mengurangi kredit berdasarkan peristiwa waktu nyata. Anda juga dapat mengurangi kredit secara manual melalui dashboard atau API.
  </Step>

  <Step title="Credits Expire or Roll Over">
    Pada akhir siklus penagihan (atau setelah periode kedaluwarsa yang dikonfigurasi), kredit yang tidak terpakai akan kedaluwarsa atau bergulir ke periode berikutnya berdasarkan pengaturan Anda.
  </Step>

  <Step title="Overage Handling">
    Jika kredit habis di tengah siklus, Anda dapat memungkinkan kelebihan (penggunaan yang dilanjutkan melebihi saldo) dan memilih cara menangani kelebihan tersebut - maaf atau data, tagih, atau bawakan defisit ke depan.
  </Step>
</Steps>

### Sumber Pemberian

Kredit dapat diberikan dari beberapa sumber:

| Sumber        | Deskripsi                                                                                  |
| ------------- | ------------------------------------------------------------------------------------------ |
| **Langganan** | Kredit diterbitkan dengan pembelian langganan, diterbitkan kembali setiap siklus penagihan |
| **Satu Kali** | Kredit diterbitkan dengan produk pembayaran satu kali                                      |
| **API**       | Kredit diberikan secara manual melalui API atau dasbor                                     |
| **Gulirkan**  | Kredit dibawa ke siklus penagihan sebelumnya                                               |

***

## Membuat Kredit

Buat hak kredit di bagian **Produk → Kredit** dari dasbor Anda. Setiap kredit mendefinisikan unit, presisi, aturan kedaluwarsa, dan perilaku siklus hidup.

<Frame caption="The Credits tab under Products shows all your credit entitlements.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Entitlements%20%20-%20Credits.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=f9f30f473d342657d3f0f857e53b2e85" alt="Halaman daftar kredit menampilkan hak kredit yang telah dibuat" style={{ maxHeight: '500px', width: 'auto' }} width="3354" height="2004" data-path="images/CBB/Desktop - Entitlements  - Credits.jpg" />
</Frame>

<Steps>
  <Step title="Navigate to Credits">
    Buka **Produk** di dasbor Anda dan pilih tab **Kredit**. Klik **Buat Kredit** untuk memulai.
  </Step>

  <Step title="Configure Basic Information">
    Masukkan **Nama Kredit** - ini adalah pengidentifikasi internal Anda untuk kredit tersebut.

    <Frame caption="The credit creation form with all configuration sections.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Create%20Credit.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=0c59e6b6eb4cfd76a545b39fb1f5c19e" alt="Formulir pembuatan kredit menampilkan info dasar, pengaturan umum, dan pengaturan langganan" style={{ maxHeight: '500px', width: 'auto' }} width="1919" height="954" data-path="images/CBB/Desktop - Create Credit.jpg" />
    </Frame>
  </Step>

  <Step title="Set General Settings">
    Konfigurasikan tipe dan properti tampilan kredit:

    <ParamField path="Credit Type" type="string" required>
      Pilih **Unit Kustom** atau **Kredit Fiat**.

      * **Unit Kustom** - Tentukan metrik Anda sendiri (token, panggilan API, jam komputasi). Memerlukan pengaturan **Nama Unit** (mis., "Platform tokens") dan **Presisi**.
      * **Kredit Fiat** - Kredit mewakili nilai mata uang sebenarnya. Memerlukan pilihan **Mata Uang Unit** (USD, EUR, GBP, INR, dll.).
    </ParamField>

    <ParamField path="Unit Name" type="string">
      Hanya untuk kredit Unit Kustom. Label yang dilihat pelanggan untuk kredit ini (mis., "Token AI", "Panggilan API"). Ditampilkan di checkout dan portal pelanggan.
    </ParamField>

    <ParamField path="Precision" type="number">
      Hanya untuk kredit Unit Kustom. Jumlah tempat desimal yang diperbolehkan:

      * `0` - Bilangan bulat (terbaik untuk item yang dapat dihitung seperti panggilan API)
      * `1` - Satu desimal (0.0)
      * `2` - Dua desimal (0.00) - **default**
      * `3` - Tiga desimal (0.000)

      <Warning>
        Presisi tidak dapat diubah setelah kredit dibuat.
      </Warning>
    </ParamField>

    <ParamField path="Credit Expiry" type="string">
      Berapa lama kredit tetap valid setelah diterbitkan:

      * **7 hari**, **30 hari** (default), **60 hari**, **90 hari**, **Kustom**, atau **Tidak Pernah**

      Pilih **Kustom** untuk menentukan jumlah hari kustom (minimal 1).
    </ParamField>
  </Step>

  <Step title="Configure Subscription Settings (Optional)">
    Pengaturan ini mengontrol perilaku kredit dalam langganan berulang:

    <ParamField path="Rollover" type="boolean">
      Izinkan kredit yang tidak terpakai untuk dibawa ke siklus penagihan berikutnya. Saat diaktifkan, konfigurasikan:

      * **Persentase Maks Gulirkan** (0–100%) - Batasi berapa banyak yang dibawa ke depan
      * **Jangka Waktu Gulirkan** - Berapa lama kredit yang digulirkan tetap valid (mis., 1 Bulan)
      * **Jumlah Maks Gulirkan** - Maksimum guliran berkelanjutan sebelum kredit hangus
    </ParamField>

    **Ketika Kredit Habis atau Langganan Kedaluwarsa:**

    <ParamField path="Allow Overage" type="boolean">
      Beri pelanggan izin untuk terus menggunakan layanan Anda setelah saldo kredit mereka mencapai nol. Saat diaktifkan, konfigurasikan:

      * **Batas Kelebihan** - Maksimum kredit yang dapat digunakan pelanggan di luar saldo mereka
      * **Harga Per Unit** - Biaya per kredit tambahan saat kelebihan diaktifkan (dengan pilihan mata uang)
    </ParamField>

    <ParamField path="Overage Behavior" type="string" required>
      Mengontrol cara menangani kelebihan di akhir siklus penagihan:

      * **Maaf atas kelebihan saat reset** (default) - Penggunaan yang melebihi batas kredit dicatat tetapi tidak ditagih. Saldo direset setiap siklus.
      * **Tagih kelebihan saat penagihan** - Penggunaan yang melebihi batas kredit dikenakan pada faktur berikutnya, kemudian saldo direset.
      * **Bawa defisit ke depan** - Penggunaan di luar batas kredit dibawa ke depan sebagai saldo negatif ke siklus berikutnya.
      * **Bawa defisit ke depan (pembayaran otomatis)** - Defisit dibawa ke depan dan dibayar otomatis dari kredit baru di siklus berikutnya.
    </ParamField>
  </Step>

  <Step title="Create Credit">
    Klik **Buat Kredit** untuk menyimpan. Kredit sekarang tersedia untuk dilampirkan ke produk apa pun.

    <Check>
      Hak kredit Anda siap. Lampirkan ke produk untuk mulai menerbitkan kredit kepada pelanggan.
    </Check>
  </Step>
</Steps>

<Tip>
  Mulailah dengan pengaturan sederhana - tanpa guliran, tanpa kelebihan - dan tambahkan kerumitan saat Anda belajar cara pelanggan menggunakan kredit. Sebagian besar pengaturan dapat diperbarui kapan saja tanpa memengaruhi pemberian yang ada. Perhatikan bahwa **presisi tidak dapat diubah** setelah kredit dibuat.
</Tip>

***

## Attaching Credits to Products

Kredit dilampirkan ke produk sebagai **hak** dalam alur pembuatan atau pengeditan produk. Anda dapat melampirkan hingga **5 kredit per produk**. Kredit berfungsi dengan ketiga jenis penetapan harga.

### Subscription Products

For subscriptions, credits are issued **per billing cycle** and can be configured with proration, trial credits, and cycle-specific settings.

<Steps>
  <Step title="Create or Edit a Subscription Product">
    Go to **Products → Create Product** or edit an existing product. Select **Subscription** as the pricing type and configure your recurring price.
  </Step>

  <Step title="Open Entitlements Section">
    Expand the **Entitlements** section and click the **Attach** button next to **Credits**.

    <Frame caption="The Entitlements section in the product form with Credits, License Key, and Digital Product Delivery options.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20Subscription.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=fb404b5c706ae200079742965a176605" alt="Bagian hak produk menampilkan tombol lampirkan Kredit" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - Subscription.jpg" />
    </Frame>
  </Step>

  <Step title="Select Credits to Attach">
    An **Add Credits** panel opens. You can select an existing credit from the dropdown or click **Create new credit** to define one on the spot.

    <Frame caption="The Add Credits panel lets you select existing credits or create new ones.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20Subscription-2.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=d67a2a18c7a550c8cf1e8378bd5514dc" alt="Panel Tambah Kredit dengan dropdown pemilihan kredit" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - Subscription-2.jpg" />
    </Frame>

    <Info>
      Anda dapat melampirkan hingga 5 kredit per produk. Setiap kredit dapat memiliki konfigurasinya sendiri.
    </Info>
  </Step>

  <Step title="Configure Credit Settings">
    For each attached credit, configure:

    <ParamField path="Credits issued per billing cycle" type="number" required>
      The number of credits granted to the customer each billing period.
    </ParamField>

    <ParamField path="Low Balance Threshold" type="number">
      Notify when credits fall below this amount. Useful for alerting customers before they run out.
    </ParamField>

    <ParamField path="Credits During Free Trial" type="number">
      Set a different credit amount for trial periods. Enable **Expire trial credits after trial ends** to revoke unused trial credits when the trial converts to a paid subscription.
    </ParamField>

    <ParamField path="Allow Proration" type="boolean">
      Prorate remaining credits when a customer upgrades or downgrades their subscription plan.
    </ParamField>

    <ParamField path="Import Default Credit Settings" type="boolean">
      Use the default rollover, overage, and expiry settings from the credit entitlement. Turn this off to customize settings specifically for this product.
    </ParamField>

    <Frame caption="Credit configuration showing per-cycle amount, trial credits, proration, and custom settings.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20Subscription-4.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=68e212dddbec73131cf9f75bf5b55408" alt="Formulir konfigurasi kredit dengan siklus penagihan, uji coba, dan pengaturan proration" style={{ maxHeight: '500px', width: 'auto' }} width="1800" height="1842" data-path="images/CBB/Desktop - Attach Credit - Subscription-4.jpg" />
    </Frame>
  </Step>

  <Step title="Review and Add">
    Review the attached credit showing name, amount, and expiration. Click **Add to Subscription** to confirm.

    <Frame caption="Review attached credits before adding them to the subscription.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20Subscription-5.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=7d8a21560061c15cc8544831a59793e2" alt="Panel Tambah Kredit menampilkan kredit yang dipilih dengan detail" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - Subscription-5.jpg" />
    </Frame>
  </Step>
</Steps>

### One-Time Payment Products

For one-time payments, credits are issued **once** at the time of purchase.

<Steps>
  <Step title="Create a One-Time Product">
    Create a product with **Single Payment** pricing type.

    <Frame caption="Single Payment pricing selected for a one-time credit product.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20OTP.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=1743cb3e515952f9d4b1b2782cebac8b" alt="Bagian harga produk dengan Pembayaran Sekali pilih" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - OTP.jpg" />
    </Frame>
  </Step>

  <Step title="Attach Credits">
    Open the **Entitlements** section and attach credits. Configure the **number of credits issued** (total one-time grant) on purchase.
  </Step>
</Steps>

<Tip>
  One-time credit products are ideal for credit top-up packs, promotional bundles, or prepaid credit purchases.
</Tip>

### Usage-Based Billing Products

For usage-based products, credits are **linked to meters** and automatically deducted based on real-time consumption events.

<Steps>
  <Step title="Create a Usage-Based Product">
    Select **Usage Based Billing** as the pricing type. Configure the base price and billing frequency.

    <Frame caption="Usage Based Billing pricing type with meter configuration.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20UBB.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=41b2862c12d126e7843098307e27e137" alt="Konfigurasi harga Berdasarkan Penggunaan" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - UBB.jpg" />
    </Frame>
  </Step>

  <Step title="Add a Meter">
    Click the **+** button in the **Select meter** section to add a meter. A subscription can have up to **3 meters**.

    <Frame caption="The Select Meter panel with meter configuration and credit toggle.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20UBB-3.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=3f677352783684107eaa7e568d9352e2" alt="Panel Pilih Meter menampilkan ambang batas gratis dan toggle kredit" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - UBB-3.jpg" />
    </Frame>
  </Step>

  <Step title="Enable Credit Billing on the Meter">
    Toggle **Bill usage in Credits** to attach a credit to the meter. Select the credit entitlement from the dropdown.

    <ParamField path="Free Threshold" type="number" required>
      The number of units that are free before credit deduction begins.
    </ParamField>

    <ParamField path="Bill usage in Credits" type="boolean">
      When enabled, meter usage deducts from the customer's credit balance instead of charging per-unit.
    </ParamField>

    <ParamField path="Meter units per credit" type="number" required>
      The number of usage units required to deduct 1 credit. For example, if set to `1000`, then 1,000 API calls consume 1 credit.
    </ParamField>

    <Frame caption="Credit attached to a meter with per-unit conversion rate.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20UBB-5.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=b4ef2fe5079cbf3bb39eb3814f101cbd" alt="Konfigurasi meter dengan pemilihan kredit dan unit meter per kredit" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="2282" data-path="images/CBB/Desktop - Attach Credit - UBB-5.jpg" />
    </Frame>
  </Step>

  <Step title="Configure Credit Issuance">
    Set the number of credits issued and optionally customize the credit settings for this product.

    <Frame caption="Configure how many credits to issue and whether to use default settings.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20UBB-6.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=22e99c54f11305a24d63c77e09a4650c" alt="Konfigurasi kredit untuk produk UBB" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Attach Credit - UBB-6.jpg" />
    </Frame>
  </Step>

  <Step title="Verify Attachment">
    Once configured, the meter shows the attached credit name, unit price, and free threshold.

    <Frame caption="Meter with credit attached showing price, threshold, and credit name.">
      <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Attach%20Credit%20-%20UBB-1.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=d1a68ef9f07872b1dc9d2b2a655df0a4" alt="Meter yang dikonfigurasi menampilkan detail lampiran kredit" style={{ maxHeight: '500px', width: 'auto' }} width="3220" height="1830" data-path="images/CBB/Desktop - Attach Credit - UBB-1.jpg" />
    </Frame>
  </Step>
</Steps>

<Info>
  When credits are linked to meters, the system automatically deducts credits based on ingested usage events. A background worker processes events every minute, aggregates them according to the meter's configuration, and applies FIFO (first-in, first-out) deduction from the customer's oldest non-expired grants.
</Info>

***

## Credit Settings

### Rollover

Rollover lets unused credits carry forward to the next billing cycle instead of expiring.

| Setting                     | Description                                                                                                         |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **Rollover Enabled**        | Toggle to allow unused credits to carry forward                                                                     |
| **Max Rollover Percentage** | Limit how much carries over (0–100%). At 50%, only half of unused credits roll over                                 |
| **Rollover Timeframe**      | How long rolled-over credits remain valid (day, week, month, year)                                                  |
| **Max Rollover Count**      | Maximum number of times credits can be consecutively rolled over. After this limit, remaining credits are forfeited |

**Example**: A customer has 200 unused credits at cycle end. With 75% rollover, 150 credits carry forward and 50 are forfeited.

### Overage

Overage controls what happens when a customer's credit balance reaches zero mid-cycle.

| Setting              | Description                                                                    |
| -------------------- | ------------------------------------------------------------------------------ |
| **Allow Overage**    | Toggle to let customers continue using the service beyond their credit balance |
| **Overage Limit**    | Maximum credits customers can consume beyond their balance                     |
| **Price Per Unit**   | Cost per additional credit consumed as overage (with currency)                 |
| **Overage Behavior** | Controls what happens to overage at the end of the billing cycle (see below)   |

**Overage Behavior options:**

| Behavior                            | Description                                                                            |
| ----------------------------------- | -------------------------------------------------------------------------------------- |
| **Forgive overage at reset**        | Usage beyond the credit limit is tracked but not billed. Balance resets each cycle     |
| **Bill overage at billing**         | Usage beyond the credit limit is charged on the next invoice, then the balance resets  |
| **Carry over deficit**              | Overage carries forward as a negative balance into the next cycle                      |
| **Carry over deficit (auto-repay)** | Deficit carries forward and is automatically repaid from new credits in the next cycle |

<Info>
  When overage is disabled, customers cannot use the service once their credit balance reaches zero. Choose an overage behavior that matches your billing model - **Forgive at reset** is the default and simplest option.
</Info>

### Expiration

| Setting                              | Description                                                                          |
| ------------------------------------ | ------------------------------------------------------------------------------------ |
| **Credit Expiry**                    | Duration after issuance before credits expire (7, 30, 60, 90, custom days, or never) |
| **Trial Credits Expire After Trial** | Whether trial-specific credits expire when the trial period ends                     |

<Info>
  Expired credits create a `CreditExpired` ledger entry. If rollover is enabled, the rollover percentage is applied before expiration, and only the remainder expires.
</Info>

***

## Usage Billing with Credits

When credits are linked to usage meters, the system creates a powerful consumption-based billing model. Customers receive a credit allocation, and usage events automatically deduct from their balance.

<Frame caption="The Usage Billing dashboard shows meter events with units consumed, credits consumed, and customer details.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Usage%20Billing.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=de8c5992d0ae59e74bbb8a840e07454f" alt="Dashboard Penagihan Penggunaan menampilkan tabel acara dengan kredit yang dikonsumsi" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Usage Billing.jpg" />
</Frame>

### How Meter-Based Credit Deduction Works

1. **Aplikasi Anda mengirimkan acara penggunaan** - Setiap acara mencakup ID pelanggan, nama acara, dan metadata
2. **Meters menggabungkan acara** - Menggunakan agregasi Count, Sum, Max, atau Last
3. **Kredit dipotong secara otomatis** - Seorang pekerja latar belakang memproses acara setiap menit, mengonversi satuan meter ke kredit menggunakan tarif yang Anda konfigurasi, dan memotong saldo pelanggan menggunakan urutan FIFO (pemberian tertua terlebih dahulu)
4. **Penggunaan berlebih dilacak** - Jika saldo kredit mencapai nol dan penggunaan berlebih diaktifkan, sistem melacak penggunaan berlebih untuk penagihan akhir siklus

### Meters Panel

The Usage Billing dashboard includes a **Meters** panel listing all defined meters with their aggregation type:

| Agregasi  | Deskripsi                     | Contoh                         |
| --------- | ----------------------------- | ------------------------------ |
| **Count** | Jumlah total acara            | Panggilan API                  |
| **Sum**   | Jumlah dari field nilai       | Total byte yang ditransfer     |
| **Max**   | Nilai tertinggi yang tercatat | Pengguna bersamaan puncak      |
| **Last**  | Nilai terbaru                 | Penyimpanan saat ini digunakan |

***

## Customer Experience

### Checkout

When a customer purchases a product with attached credits, the checkout page displays the included credits as part of the product offering.

<Frame caption="Checkout shows included credits with the product, making the value proposition clear.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Checkout.png?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=21880df0e4b0b1a3cb8593dbeb8ae343" alt="Halaman pembayaran menampilkan produk dengan kredit panggilan API yang termasuk" style={{ maxHeight: '500px', width: 'auto' }} width="1440" height="960" data-path="images/CBB/Checkout.png" />
</Frame>

Credits appear in an **Includes** section below the product description, showing the credit amount and type (e.g., "\$1000 API calls").

### Customer Portal

Customers can view and manage their credit balances in the Customer Portal under the **Credits** section.

<Frame caption="The Customer Portal shows available balance and full transaction history.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Customer%20Portal.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=b8afe1f89242f9e347b26b990dd00fe8" alt="Tampilan portal pelanggan dengan saldo dan riwayat transaksi" style={{ maxHeight: '500px', width: 'auto' }} width="3016" height="2030" data-path="images/CBB/Customer Portal.jpg" />
</Frame>

The portal displays:

* **Available Balance** - Current credit balance displayed prominently
* **Credit Tabs** - Switch between different credit types (e.g., "OpenAI Credits", "Usage Tokens")
* **Recent Transactions** - Full history with date, transaction ID, type, amount, and running balance

Transaction types shown to customers include:

| Type                          | Description                                       | Amount    |
| ----------------------------- | ------------------------------------------------- | --------- |
| **Credits with Subscription** | Credits issued with subscription purchase/renewal | Green (+) |
| **One-Time Credits**          | Credits from one-time purchases or manual grants  | Green (+) |
| **Usage Deduction**           | Credits consumed through service usage            | Red (-)   |
| **Overage**                   | Usage beyond credit balance                       | Red (-)   |

### Subscription Details

The subscription detail page shows credit entitlements alongside other plan information.

<Frame caption="Subscription details show credit allocation, remaining balance, and renewal date.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Subscription%20Details.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=059f57f8996c1f514b9d7eba1ef6e33a" alt="Halaman detail langganan menampilkan hak dan riwayat penggunaan" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1984" data-path="images/CBB/Desktop - Subscription Details.jpg" />
</Frame>

Key information displayed:

* **Credit allocation** per billing cycle (e.g., "1000 credits each cycle")
* **Remaining balance** (e.g., "7500 credits remaining")
* **Renewal date** for next credit issuance
* **Usage History** tab with meter-level breakdown showing units consumed, thresholds, unit prices, and total costs

### Transaction Details

Payment transaction pages include an **Entitlements** section showing all entitlements delivered with the payment, including credits.

<Frame caption="Transaction details show credits alongside other entitlements like license keys and digital downloads.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Transactions%20-%20Payment%20Summary.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=dccb0ada7682ead4493baf71199a86fb" alt="Halaman detail transaksi menampilkan hak kredit" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="2752" data-path="images/CBB/Desktop - Transactions - Payment Summary.jpg" />
</Frame>

***

## Managing Credits

### Dashboard Views

#### Credit Entitlements List

View all your credit entitlements in **Products → Credits**. The table shows credit name, expiry settings, and provides quick actions for editing or archiving.

<Frame caption="Credits listing with total count, creation button, and management actions.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Entitlements%20%20-%20Credits.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=f9f30f473d342657d3f0f857e53b2e85" alt="Halaman daftar kredit di bagian Produk" style={{ maxHeight: '500px', width: 'auto' }} width="3354" height="2004" data-path="images/CBB/Desktop - Entitlements  - Credits.jpg" />
</Frame>

#### Customer Credit Details

View a specific customer's credit balances and transaction history from **Customers → \[Customer Name] → Credits**.

<Frame caption="Customer detail page showing credit balance and full transaction ledger.">
  <img src="https://mintcdn.com/dodopayments/ibNfoFRyCIGyt3pO/images/CBB/Desktop%20-%20Customer%20Details.jpg?fit=max&auto=format&n=ibNfoFRyCIGyt3pO&q=85&s=a52e7e914338d698bf72498821f6a8b6" alt="Halaman detail pelanggan dengan tab Kredit menampilkan saldo dan transaksi" style={{ maxHeight: '500px', width: 'auto' }} width="2880" height="1920" data-path="images/CBB/Desktop - Customer Details.jpg" />
</Frame>

The customer credit view includes:

* **Credit Selector** - Switch between different credit entitlements
* **Available Balance** - Current balance in large, prominent display
* **Apply Credit/Debit** - Button to manually adjust the customer's balance
* **Recent Transactions** - Full ledger with date, transaction ID, type, amount, and running balance

### Manual Adjustments

You can manually credit or debit a customer's balance directly from the dashboard:

<Steps>
  <Step title="Navigate to Customer">
    Go to **Customers** and select the customer.
  </Step>

  <Step title="Open Credits Tab">
    Click the **Credits** tab and select the appropriate credit entitlement from the wallet selector.
  </Step>

  <Step title="Apply Credit or Debit">
    Click **Apply Credit/Debit** to open the adjustment interface.

    <ParamField path="Transaction Type" type="string" required>
      Select **Credit** to add credits or **Debit** to remove credits from the customer's balance.
    </ParamField>

    <ParamField path="Amount" type="number" required>
      The number of credits to add or remove.
    </ParamField>

    <ParamField path="Reason" type="string">
      Optional explanation for the adjustment (e.g., "Service compensation", "Promotional bonus").
    </ParamField>
  </Step>

  <Step title="Confirm">
    Review and apply the adjustment. The change is reflected immediately in the customer's balance and recorded in the credit ledger.

    <Check>
      Manual adjustments create a `ManualAdjustment` ledger entry with full audit trail.
    </Check>
  </Step>
</Steps>

### Credit Ledger

Every credit operation is recorded in the credit ledger, providing a complete audit trail:

| Transaction Type       | Description                                               |
| ---------------------- | --------------------------------------------------------- |
| **Credit Added**       | Credits granted (subscription, one-time, or API)          |
| **Credit Deducted**    | Credits consumed through usage or manual debit            |
| **Credit Expired**     | Credits expired without rollover                          |
| **Credit Rolled Over** | Credits carried forward to the next period                |
| **Rollover Forfeited** | Rolled credits forfeited after max rollover count reached |
| **Overage Charged**    | Usage beyond credit balance with overage enabled          |
| **Auto Top-Up**        | Automatic credit replenishment at low balance             |
| **Manual Adjustment**  | Credit or debit applied manually by merchant              |
| **Refund**             | Credits refunded                                          |

Each ledger entry records the balance before and after the transaction, overage before and after, a description, and reference to the source (payment, subscription, etc.).

***

## Webhooks

Credit-Based Billing fires webhook events for every credit lifecycle change. Use these to keep your application in sync with credit balances, trigger notifications, or build custom billing workflows.

| Event                       | Description                                    |
| --------------------------- | ---------------------------------------------- |
| `credit.added`              | Credits granted to a customer                  |
| `credit.deducted`           | Credits consumed through usage or manual debit |
| `credit.expired`            | Unused credits expired                         |
| `credit.rolled_over`        | Credits carried forward to a new grant         |
| `credit.rollover_forfeited` | Credits forfeited at max rollover count        |
| `credit.overage_charged`    | Overage charges applied                        |
| `credit.manual_adjustment`  | Manual credit/debit adjustment made            |
| `credit.balance_low`        | Balance dropped below configured threshold     |

Semua acara buku besar (`credit.added` hingga `credit.manual_adjustment`) mencakup payload lengkap `CreditLedgerEntry` dengan saldo sebelum/sesudah, kelebihan sebelum/sesudah, referensi sumber, dan `metadata` dari langganan sumber hibah atau pembayaran (kosong untuk hibah yang dibuat langsung melalui API). Acara `credit.balance_low` mencakup konfigurasi ambang batas dan saldo saat ini.

<Card title="Credit Webhook Payloads" icon="bell" href="/developer-resources/webhooks/intents/credit">
  View full payload schemas, field descriptions, and integration examples for all credit webhook events.
</Card>

***

## API Management

<AccordionGroup>
  <Accordion title="Create Credit Entitlements">
    Use the API to create credit entitlements programmatically with full control over rollover, overage, and expiration settings.

    <CardGroup cols={2}>
      <Card title="Create Credit Entitlement" icon="plus" href="/api-reference/credit-entitlements/create-credit-entitlement">
        Create a new credit entitlement with rollover, overage, and expiry configuration.
      </Card>

      <Card title="List Credit Entitlements" icon="list" href="/api-reference/credit-entitlements/list-credit-entitlements">
        Retrieve all credit entitlements for your business.
      </Card>
    </CardGroup>
  </Accordion>

  <Accordion title="Manage Credit Entitlements">
    Retrieve, update, or delete credit entitlements. Deleted entitlements can be restored.

    <CardGroup cols={2}>
      <Card title="Get Credit Entitlement" icon="magnifying-glass" href="/api-reference/credit-entitlements/get-credit-entitlement">
        Retrieve a specific credit entitlement by ID.
      </Card>

      <Card title="Update Credit Entitlement" icon="pen" href="/api-reference/credit-entitlements/update-credit-entitlement">
        Update rollover, overage, expiry, or other settings.
      </Card>

      <Card title="Delete Credit Entitlement" icon="trash" href="/api-reference/credit-entitlements/delete-credit-entitlement">
        Soft-delete a credit entitlement.
      </Card>

      <Card title="Undelete Credit Entitlement" icon="rotate-left" href="/api-reference/credit-entitlements/undelete-credit-entitlement">
        Restore a previously deleted credit entitlement.
      </Card>
    </CardGroup>
  </Accordion>

  <Accordion title="Grant and Adjust Credits">
    Grant credits directly to a customer's balance without requiring a purchase, or create manual debit entries for billing adjustments.

    <Card title="Create Ledger Entry" icon="plus" href="/api-reference/credit-entitlements/create-ledger-entry">
      Credit or debit a customer's balance with full audit trail and idempotency support.
    </Card>
  </Accordion>

  <Accordion title="Query Balances and Ledger">
    Retrieve a customer's current credit balance, grant history, and full ledger of transactions for any credit entitlement.

    <CardGroup cols={2}>
      <Card title="List Balances" icon="wallet" href="/api-reference/credit-entitlements/list-balances">
        List all customer balances for a credit entitlement.
      </Card>

      <Card title="Get Customer Balance" icon="user" href="/api-reference/credit-entitlements/get-customer-balance">
        Get a specific customer's balance.
      </Card>

      <Card title="List Customer Grants" icon="gift" href="/api-reference/credit-entitlements/list-customer-grants">
        View all credit grants for a customer.
      </Card>

      <Card title="List Customer Ledger" icon="scroll" href="/api-reference/credit-entitlements/list-customer-ledger">
        Full transaction history for a customer.
      </Card>
    </CardGroup>
  </Accordion>
</AccordionGroup>

### Integration Example

Inisialisasi klien Dodo Payments:

```typescript theme={null}
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'],
  environment: 'test_mode', // defaults to 'live_mode'
});
```

Lampirkan kredit ke produk langganan saat checkout:

```typescript theme={null}
const session = await client.checkoutSessions.create({
  product_cart: [
    {
      product_id: 'prod_ai_pro_plan',
      quantity: 1,
    }
  ],
  customer: { email: 'customer@example.com' },
  return_url: 'https://yourapp.com/success'
});
```

Kirim event penggunaan yang secara otomatis mengurangi kredit:

```typescript theme={null}
await client.usageEvents.ingest({
  events: [{
    event_id: `gen_${Date.now()}`,
    customer_id: 'cus_abc123',
    event_name: 'ai.generation',
    timestamp: new Date().toISOString(),
    metadata: { model: 'gpt-4', tokens: 1500 }
  }]
});
```

***

## Contoh Dunia Nyata

<AccordionGroup>
  <Accordion title="AI SaaS Platform">
    **Struktur Harga:**

    | Plan       | Price    | Credits/Month    | Overage       |
    | ---------- | -------- | ---------------- | ------------- |
    | Starter    | \$29/mo  | 10,000 tokens    | \$0.003/token |
    | Pro        | \$99/mo  | 100,000 tokens   | \$0.002/token |
    | Enterprise | \$499/mo | 1,000,000 tokens | \$0.001/token |

    **Konfigurasi:**

    * Jenis Kredit: Unit Khusus ("AI Tokens")
    * Presisi: 0 (token utuh)
    * Rollover: Maks 25%, jangka waktu 1 bulan
    * Overage: Diaktifkan, tagih overage saat penagihan
    * Meter: `ai.generation` dengan agregasi Sum pada bidang `tokens`
  </Accordion>

  <Accordion title="API Gateway">
    **Struktur Harga:**

    | Plan      | Price   | Credits/Month | Overage       |
    | --------- | ------- | ------------- | ------------- |
    | Free      | \$0/mo  | 1,000 calls   | Blocked       |
    | Developer | \$19/mo | 50,000 calls  | \$0.001/call  |
    | Business  | \$99/mo | 500,000 calls | \$0.0005/call |

    **Konfigurasi:**

    * Jenis Kredit: Unit Khusus ("API Calls")
    * Presisi: 0 (panggilan utuh)
    * Rollover: Dinonaktifkan
    * Overage: Paket Developer+ mengizinkan overage (diampuni saat reset), paket Free menonaktifkan overage
    * Meter: `api.request` dengan agregasi Count
  </Accordion>

  <Accordion title="Cloud Storage Service">
    **Struktur Harga:**

    | Plan     | Price   | Credits/Month  | Overage        |
    | -------- | ------- | -------------- | -------------- |
    | Personal | \$9/mo  | 100 GB-hours   | \$0.05/GB-hour |
    | Team     | \$49/mo | 1,000 GB-hours | \$0.03/GB-hour |

    **Konfigurasi:**

    * Jenis Kredit: Unit Khusus ("GB-hours")
    * Presisi: 2 (dua tempat desimal)
    * Rollover: Maks 50%, digulirkan sekali
    * Overage: Diaktifkan dengan batas 200%
    * Meter: `storage.usage` dengan agregasi Sum
  </Accordion>
</AccordionGroup>

***

## Praktik Terbaik

* **Mulailah dengan sederhana**: Mulailah dengan satu jenis kredit dan tanpa rollover. Tambahkan kompleksitas berdasarkan umpan balik pelanggan dan pola penggunaan.
* **Tetapkan ekspektasi yang jelas**: Tampilkan alokasi kredit, sisa saldo, dan harga kelebihan dengan jelas di halaman produk dan portal pelanggan Anda.
* **Gunakan satuan yang bermakna**: Namai kredit sesuai dengan apa yang mereka wakili (misalnya, "API Calls", "AI Tokens") daripada istilah umum. Ini membantu pelanggan memahami nilai.
* **Konfigurasikan kedaluwarsa dengan hati-hati**: Jendela kedaluwarsa pendek (7 hari) mendorong urgensi tetapi dapat membuat pelanggan frustrasi. Jendela yang lebih panjang (30–90 hari) lebih ramah pelanggan untuk sebagian besar produk SaaS.
* **Pantau saldo rendah**: Tetapkan ambang batas saldo rendah untuk memperingatkan pelanggan sebelum kehabisan, mengurangi kejutan biaya kelebihan.
* **Uji dalam mode uji**: Buat kredit, lampirkan ke produk uji, dan simulasi siklus pembelian → penggunaan → pengurangan → kedaluwarsa sepenuhnya sebelum ditayangkan.

<Info>
  Penagihan Berbasis Kredit berfungsi dengan mulus dengan semua fitur Dodo Payments lainnya - langganan dengan uji coba, perubahan rencana dengan prorata, dan portal pelanggan. Mulailah dengan pengaturan dasar dan kembangkan saat model harga Anda berkembang.
</Info>
