Skip to main content
Pay-per-use (usage-based) pricing charges customers based on how much of a feature they actually consume, billed at the end of each billing period. This is ideal for products where usage varies significantly between customers.
Example
A notification service charges 1per1,000notificationssent.Acustomerwhosends5,000notificationsinamonthpays1 per 1,000 notifications sent. A customer who sends 5,000 notifications in a month pays 5 at the end of that month.

Setting up

Create a consumable feature with a usage_based price:
autumn.config.ts
import { feature, item, plan } from 'atmn';

export const notifications = feature({
  id: 'notifications',
  name: 'Notifications',
  type: 'metered',
  consumable: true,
});

export const payAsYouGo = plan({
  id: 'pay_as_you_go',
  name: 'Pay As You Go',
  group: 'main',
  items: [
    item({
      featureId: notifications.id,
      included: 1000,
      reset: { interval: 'month' },
      price: {
        amount: 1,
        interval: 'month',
        billingUnits: 1000,
        billingMethod: 'usage_based',
      },
    }),
  ],
});
Push changes with atmn push.

How it works

  1. A customer’s usage is tracked via the track endpoint throughout the billing period
  2. Usage first draws down from the included amount (if any) at no charge
  3. Usage beyond the included amount is overage — billed at the configured rate
  4. At the end of the billing period, Autumn generates a Stripe invoice for the total overage
Usage-based features allow overage by default. The check endpoint will return allowed: true even if the customer has exceeded their included balance, as long as a usage-based price is configured.

Tracking usage

Track usage as it occurs — Autumn accumulates it over the billing period:
import { Autumn } from "autumn-js";

const autumn = new Autumn({ secretKey: "am_sk_..." });

await autumn.track({
  customer_id: "user_123",
  feature_id: "notifications",
  value: 500,
});

Checking access

Check if the customer can use the feature. For usage-based features with overage, allowed is true as long as the feature exists on the customer’s plan:
const { data } = await autumn.check({
  customer_id: "user_123",
  feature_id: "notifications",
});

console.log(data.allowed); // true (overage allowed)
console.log(data.balance);

Combining with free tiers

A common pattern is pairing usage-based pricing with a free plan. Free users are blocked when they exceed their limit, while paying users are billed for overages.
PlanOver limitResult
FreeYesBlocked (allowed: false)
Pay-as-you-goYesAllowed, billed at end of period