Back to Documentation

GUIDES

Usage-Based Billing

Report customer usage for metered and hybrid billing products

Billing Models

Revnu supports three billing models:

ModelFlat FeeUsage Charges
FlatFixed monthly or one-time priceNone
MeteredNonePay per unit of usage
HybridFixed monthly feePlus usage charges on top

For metered and hybrid products, your app reports usage events via the API. Stripe aggregates usage over the billing period and invoices customers automatically.

API Endpoint

POST/api/v1/usage

Report a usage event for a customer.

Headers

Authorization: Bearer rev_xxxxx
Content-Type: application/json

Request Body

{
  "productId": "k57abc123...",
  "stripeCustomerId": "cus_xxxxx",
  "value": 150
}
FieldTypeDescription
productIdstringYour Revnu product ID
stripeCustomerIdstringThe Stripe customer ID (from the purchase record)
valueintegerUsage amount (must be a positive whole number)

Success Response (200)

{
  "success": true,
  "value": 150,
  "eventName": "api_calls"
}

Error Responses

StatusDescription
400Value must be a positive whole number, or product does not support metered billing
401Invalid API key
404Product not found
429Rate limit exceeded (500 requests per minute per creator)
502Failed to report usage to Stripe

Integration Example

// Report usage from your app's backend
async function reportUsage(customerId: string, units: number) {
  const response = await fetch("https://your-store.revnu.app/api/v1/usage", {
    method: "POST",
    headers: {
      "Authorization": "Bearer rev_your_api_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      productId: "your_product_id",
      stripeCustomerId: customerId,
      value: units,
    }),
  });

  if (!response.ok) {
    const error = await response.json();
    console.error("Usage report failed:", error);
  }
}

// Example: report 1 unit per API call
app.use("/api/*", async (req, res, next) => {
  next();
  // Report usage (fire and forget)
  reportUsage(req.customerId, 1).catch(console.error);
});

Important Notes

Values must be whole numbers. Use 1 for "1 API call", not 0.5.

Report usage as it happens. Don't batch over long periods. Stripe aggregates for you.

Rate limit: 500 requests per minute per creator. For higher throughput, batch multiple units into a single event (e.g., value: 100 instead of 100 separate events).

First invoice for metered subscriptions only includes the flat fee (if hybrid). Usage charges appear on the second invoice onwards.

Finding the Stripe Customer ID

The stripeCustomerId is available in the purchase record after checkout. You can:

  • Query GET /api/v1/access?email=customer@example.com
  • Store it in your own database when you receive the checkout webhook
  • Look it up in the Revnu dashboard under Purchases