Skip to content
onchain-engineeringusage-billingstablecoin-api
Joshua C.

Build Usage-Based USDC Billing with Capped Recurring Flows

Learn how to implement usage-based USDC billing with capped recurring approvals and real-time webhooks, including a worked example and integration details.

Build Usage-Based USDC Billing with Capped Recurring Flows

Most SaaS teams start with simple recurring billing. Usage-based pricing comes later, often once customers expect to pay for what they use, not just for a flat subscription. Onchain, with USDC, usage billing needs a flow that can meter consumption, trigger payments up to a cap, and notify your backend in real time. This guide shows how to build that with capped recurring USDC payments, usage tracking and webhooks for instant feedback.

Why Usage Billing Needs a Different Onchain Flow

Traditional SaaS usage billing charges a card for whatever the meter shows at the end of the cycle. Onchain, a stablecoin payment is always explicit. USDC moves from the customer’s wallet only when a signed transaction confirms onchain. That means you need to:

  • Meter usage internally.
  • Collect payment up to a signed cap.
  • Trigger collection at renewal or when usage hits a threshold.
  • Respond in real time to success or failure.

With a capped recurring flow, you get a recurring approval: the customer sets a USDC spending limit, visible and signed in their wallet. You can collect up to that cap per cycle. No more. The customer cannot be charged above the cap unless they sign a new approval.

Key Components: Cap, Meter, Trigger, Notify

A complete usage billing system for onchain stablecoins has four moving parts:

  1. Recurring Cap: Set by the customer, this is the maximum USDC you can collect in a given cycle.
  2. Usage Meter: Your backend tracks customer usage for the cycle, in units that map to price.
  3. Trigger: When usage is billed (end of month, or on threshold), your system calls the billing API to collect the amount, up to the cap.
  4. Webhook: Your backend receives a webhook when payment is confirmed or fails, so you can unlock features or pause service.

Worked Example: API Calls and Dollar Values

Suppose you run an AI image service. Pricing is $0.20 per image, billed in USDC at the end of each month. Most customers set a $50 cap per month, 250 images max. If a customer uses 180 images in June, you will bill 180 × $0.20 = $36.00 in USDC.

Step 1: Customer Sets a Billed Cap

At signup or in-app, show the customer a billing cap prompt:

  • “Approve up to $50 USDC for monthly billing.”
  • Customer signs the approval in their wallet (no seed phrase, no private key given to you).

Onchain, this binds your app to the cap. You cannot collect more unless they approve a new, higher cap.

Step 2: Meter Usage in Your Backend

Your backend tracks usage per customer:

# Example: Python pseudocode for metering
usage = get_image_count(customer_id, cycle_start, cycle_end)
amount_due = min(usage * 0.20, cap)

You do not need to touch the chain for metering. Usage stays internal until it’s time to bill.

Step 3: Trigger Collection at Cycle End

At the end of the billing period (e.g., June 30, 23:59 UTC), initiate the collection:

  • If amount_due is less than the cap, collect the actual usage cost.
  • If usage exceeds the cap, collect only up to the cap.

This is a call to Reclack’s API or a webhook from your scheduler. Example (simplified):

POST /api/collect
{
    "customer": "0xC0FFEE...",
    "amount": 36.00,
    "chain": "base",
    "cycle_id": "2023-06"
}

Reclack attempts to collect $36 in USDC from the customer’s wallet, never exceeding the cap.

Step 4: Handle Real-Time Webhook Notification

When the payment confirms onchain, Reclack sends a webhook to your backend. This includes:

  • The customer identifier (wallet address or your internal ID).
  • The cycle and amount settled.
  • The transaction hash.
  • Success or failure status.

Example webhook payload:

{
  "event": "usdc_payment_settled",
  "customer": "0xC0FFEE...",
  "cycle": "2023-06",
  "amount": "36.00",
  "tx_hash": "0xdeadbeef...",
  "status": "success"
}

You update your records, unlock features, or send a receipt. If the webhook shows failure (insufficient funds, cap revoked, or gas error), you can prompt the customer to retry, send an in-app notice, or pause service.

What Happens When Usage Hits the Cap Mid-Cycle

If a customer uses the full cap before the billing period ends, for example, 250 images at $0.20 each ($50 total) by June 20, your backend detects the cap is reached. You can:

  • Trigger an immediate collection for the cap amount.
  • Notify the customer they have used their monthly limit.
  • Optionally, prompt them to raise their cap for more usage.

No further collection is possible until the next cycle or the cap is raised. The customer must sign any new cap in their wallet.

Handling Failures: What Fails and How to Respond

Onchain payments can fail for a few reasons:

  • Customer wallet has insufficient USDC.
  • Cap has been reduced or revoked onchain.
  • Gas fees are too high or not covered by the customer.

Reclack’s webhook notifies you of the failure. Do not retry the same collection without action from the customer. Instead, show a clear message (“Please top up your wallet or increase your cap”) and provide a prompt to retry or raise the cap. Once the customer takes action, you can trigger collection again.

Integrating with Existing SaaS or Platform

Reclack does not require a plugin or app for most platforms. You can:

  • Use a hosted checkout link for customer approval.
  • Embed the widget in your billing page.
  • Call the API from your billing system or scheduler.
  • Listen for webhook events to update your usage records and unlock features.

You do not need to handle private keys, seed phrases, or custody of funds. All funds settle directly from the customer wallet to your own settlement address.

Real-Time Webhooks: Event-Driven Usage Billing

Webhooks are critical for a responsive user experience. They let your system react to payment events without polling or guesswork. Typical events include:

  • usdc_payment_settled: Payment succeeded and is final.
  • usdc_payment_failed: Payment attempt failed. Includes reason (insufficient funds, cap revoked, gas failure).
  • usdc_cap_updated: Customer signed a new cap or revoked an existing one.

Listen for these events in your backend. Use them to unlock features, send receipts, or prompt the customer for action. Because onchain settlement is final, once you receive a usdc_payment_settled event, you can safely deliver service or credits.

Usage Billing Beyond the Basics: Mid-Cycle Triggers and Alerts

Some SaaS teams want mid-cycle collection: bill whenever usage hits a threshold, not just at the end of the month. With capped recurring approvals, you can do this:

  • Track usage internally.
  • When usage × price approaches the cap (say, within 90%), send an alert.
  • As soon as usage reaches the cap, trigger collection immediately.
  • If the customer raises their cap, continue collection. Each cap change requires a new approval onchain.

This pattern supports both predictable monthly billing and flexible pay-as-you-go, without exposing the customer to unlimited charges.

Practical Notes

  • Every recurring approval is bounded. Reclack never asks for unlimited spend.
  • Payment is always pulled from the customer’s wallet, never held by Reclack.
  • You can run this flow on Arc, Base, Ethereum, or Polygon, with settlement in USDC.
  • Webhooks are the source of truth for payment status. Do not deliver service until you receive confirmation.

Building usage-based billing onchain means more explicit control for both sides. Customers see and sign exactly what they authorize. Merchants get instant, final settlement with no chargebacks.

We built Reclack for these flows: capped recurring approvals, usage metering, and real-time webhooks that drive your SaaS or platform logic. You can start with a hosted checkout, embed the widget, or go fully custom with the API and webhook system. Learn more at reclack.com.

onchain-engineeringusage-billingstablecoin-api