Billing
Usage billing and add-ons
Bill what customers use, sell add-ons on a subscription, and invoice every part of a period on renewal.
Overview
A meter counts usage events per customer. A metered pricebills a meter's usage for each billing period, after any included units, per unit or by tiers. Add-onsare extra prices on a subscription: recurring ones bill every period with a quantity, one-time ones go on the next invoice. On every renewal PaymentHooks builds one invoice with all of it, taxes each line, then charges it. All amounts are integers in the smallest currency unit of the subscription's itemLocalCurrency. Endpoints use the subscriptions:read / subscriptions:write scopes.
Meters
curl https://paymenthooks.com/api/v1/meters \
-X POST \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{ "displayName": "API requests", "eventName": "api_request", "aggregation": "sum" }'| Field | Type | Description |
|---|---|---|
displayName | string | Name shown in the dashboard and on the customer's billing page (max 120 characters). |
eventName | string | The name usage is reported under. Letters, digits, _ . : -; unique per account; cannot change later. |
aggregation | stringDefault: | How a period's events become one quantity: sum (total of values), count (number of events), max (largest value) or last (latest value). Cannot change later. |
customerMappingKey | stringDefault: | Key in the event payload that holds the PaymentHooks customer id. |
valueKey | stringDefault: | Key in the event payload that holds the whole-number value. Optional for count meters (each event counts 1). |
GET /meters lists meters, GET /meters/:id retrieves one, PATCH /meters/:id changes displayName or status (active / inactive), and GET /meters/:id/usage returns the aggregated usage per customer for from / to (default: the last 30 days) with the latest events.
Report usage
curl https://paymenthooks.com/api/v1/meter-events \
-X POST \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{
"eventName": "api_request",
"identifier": "req_2026_11_04_0001",
"timestamp": "2026-11-04T10:15:00Z",
"payload": { "customerId": "ph_cus_8f14e45fceea167a5a36dedd4bea2543", "value": 25 }
}'| Field | Type | Description |
|---|---|---|
eventName | string | The meter's eventName. An unknown name answers 404; an inactive meter answers 422 METER_INACTIVE. |
payload | object | Holds the customer id (under the meter's customerMappingKey) and the value (under its valueKey), a non-negative whole number. |
identifier | string | Idempotency key of the event (max 255 characters). Defaults to the Idempotency-Key header; one of the two is required. A repeat returns 200 with the recorded event; a repeat with different data returns 409 CONFLICT. |
timestamp | string | numberDefault: | When the usage happened: ISO 8601 or Unix seconds, at most 35 days in the past and not in the future. Decides the billing period it counts in. |
Metered prices
Create a recurring price with usageType: "metered" and the meter's id (POST /prices). Example: 10,000 requests included, then graduated tiers: [{ upTo: 100000, unitAmount: 2 }, { upTo: null, unitAmount: 1 }]. A metered price can be the subscription's base price or an add-on.
In the dashboard, choose Pricing model: Usage-based on Prices → Create Price, pick the meter (its aggregation is shown), set the included units and choose per-unit or tiered (graduated or volume) billing. Prices are typed in major units of the price currency (e.g. 0.02 USD per request); the API takes the smallest unit (2).
| Field | Type | Description |
|---|---|---|
usageType | stringDefault: | metered: billed from the meter's usage in each period. licensed: billed for the quantity. |
meterId | string | Required for metered prices: one of your meters. |
includedQuantity | integerDefault: | Units included in every period before any charge (overage pricing). Metered prices only. |
billingScheme | stringDefault: | per_unit: billable units x itemLocalCurrencyAmount. tiered: priced by tiers. |
tiersMode | string | graduated: each unit priced by its own tier plus every reached tier's flatAmount. volume: every unit priced by the tier the total falls in, plus its flatAmount. |
tiers | array | [{ upTo, unitAmount, flatAmount? }] in the smallest currency unit, upTo increasing, the last one null. |
Add-ons
POST /subscriptions/:id/items adds a recurring add-on; PATCH .../items/:itemId changes its quantity; DELETE .../items/:itemIdremoves it. Mid-period changes are prorated on the real period length unless the subscription's prorationBehavior is none: the difference is a proration line on the next invoice (a credit when negative). POST /subscriptions/:id/invoice-items queues a one-time add-on for the next invoice; DELETE .../invoice-items/:id removes it before it is invoiced. GET /subscriptions/:id/items lists both.
| Field | Type | Description |
|---|---|---|
priceId | string | A price in the subscription's currency. Recurring add-ons (POST .../items) need a recurring price on the subscription's interval; one-time add-ons (POST .../invoice-items) need a one-time price. |
quantity | integerDefault: | 1 to 10000. Metered add-ons have no quantity (billed from usage). |
description | string | One-time add-ons only: the invoice line text (defaults to the price name). |
Renewal invoice
Before a renewal is charged, the period invoice is built: the base price, every recurring add-on, every metered price (usage from the period start to its end), and every pending one-time or proration item. Each line is taxed by its own price's tax behaviour or tax-table rate, otherwise at the rate agreed at checkout. The customer's account balance is used first; the rest is charged, and the paid invoice lists every line. Credits larger than the period's charges are added to the customer's balance. GET /subscriptions/:id/upcoming-invoice previews the next invoice with the usage so far, and an invoice.upcomingwebhook (Stripe's shape) is sent a few days before each renewal.
Feature types
A feature is one thing a plan can include. Its type decides how usage is counted and what a product can set for it. The type, key, meter and reset interval are fixed once the feature exists: your app checks the key, and running subscriptions are snapshotted against the type.
| Field | Type | Description |
|---|---|---|
boolean | on / off | Included or not, e.g. priority support or single sign-on. No unit and no maximum. Customers see the feature name. |
quantity | count in use | How many the customer has at a time, e.g. 3 projects or 10 seats. Your app reports the current count with PUT /customers/{id}/feature-usage/{key}. Never resets. Overage is always restrict (bill seats with a per-unit price and the subscription quantity). |
metered | usage per period | Usage counted by a meter (sum or count) in each period, e.g. 5,000 API calls a month. Reported with POST /meter-events. Resets with resetInterval. Overage can be restrict or bill. |
| Field | Type | Description |
|---|---|---|
billing_period | default | Usage resets at each subscription period boundary (renewal). Customers see / month for a monthly plan, / billing period when a period spans several intervals. |
month | calendar | Usage resets at 00:00 UTC on the first day of each calendar month, whatever the plan's interval. Customers see / month. |
Create and manage features
Features are defined once per account (POST /features) and reused on any number of products. GET /features lists them (status, search, page, pageSize up to 100), GET /features/{id} reads one and PATCH /features/{id} changes the name, description, unit, metadata or status. Reads need products:read, writes products:write. Every write is recorded in the audit log. In the dashboard: Catalog > Features.
curl https://paymenthooks.com/api/v1/features \
-X POST \
-H "Authorization: Bearer phk_live_..." \
-H "Idempotency-Key: feature-api-calls" \
-H "Content-Type: application/json" \
-d '{
"key": "api_calls",
"name": "API calls",
"type": "metered",
"unit": "calls",
"meterId": "ph_mtr_4b8e2d6a0c3f7b1e5d9a2c6f0b4e8d3a",
"resetInterval": "month"
}'
# 201 { "data": { "id": "ph_fea_7d2a9c4e1b6f3a8d0c5e2b7f4a9d1c6e", "key": "api_calls", "type": "metered", "status": "active", ... }, "error": null }
curl -X PATCH https://paymenthooks.com/api/v1/features/ph_fea_7d2a9c4e1b6f3a8d0c5e2b7f4a9d1c6e \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{ "status": "archived" }'| Field | Type | Description |
|---|---|---|
key | string | What your app checks, e.g. api_calls. 1-64 characters: lower-case letters, digits, _ . -, starting with a letter or digit. Unique in your account (409 CONFLICT otherwise). Cannot change. |
name | string | Name customers see on checkout and in emails (max 80 characters). |
type | string | boolean, quantity or metered. Cannot change. |
unit | string | Plural unit shown with limits, e.g. calls in "5,000 calls / month" (max 30 characters). Not allowed on boolean. Without it the feature name is used. |
meterId | string | Required for metered, refused otherwise: one of your active meters with sum or count aggregation. A max or last meter answers 409 FEATURE_METER_AGGREGATION_UNSUPPORTED; an inactive or unknown meter 400 VALIDATION_ERROR. Cannot change. |
resetInterval | stringDefault: | metered only: billing_period or month. Refused on other types. Cannot change. |
description | string | Internal description (max 500 characters). |
metadata | object | Up to 50 keys (max 40 characters) with text values (max 500 characters). |
| Field | Type | Description |
|---|---|---|
name / description / unit | string | null | Same rules as on create. description and unit accept null to clear. |
status | string | archived: the feature can no longer be added to a product; products, subscriptions and customer entitlements that already have it keep it. active restores it. There is no DELETE. |
metadata | object | Replaces the metadata. |
| Field | Type | Description |
|---|---|---|
400 VALIDATION_ERROR | all | Invalid or unknown field; error.fields names each one (for a product list, features.N.featureId / .limitValue / ...). Also: changing key, type, meterId or resetInterval on PATCH, an inactive or unknown meter, more than 50 features on a product. |
404 NOT_FOUND | all | The feature or product is not in your account. |
409 CONFLICT | POST /features | The key is already used by another of your features (archived ones included). |
409 FEATURE_METER_AGGREGATION_UNSUPPORTED | POST /features | The meter uses max or last; the usage ledger adds increments, so a feature needs a sum or count meter. |
403 INSUFFICIENT_SCOPE | all | The API key lacks products:read (reads) or products:write (writes). |
Attach features to a product
PUT /products/{productId}/featuresreplaces the product's whole list in one transaction: features you leave out are removed, and { "features": [] } removes them all. GETreturns the list in display order with each feature's key, name, type, unit and status. The product's features apply to every price of the product; overage terms are set per price (PUT /prices/{id}/feature-overage, below). Running subscriptions keep the terms they were snapshotted with until their next period; new subscriptions get the new list at once. In the dashboard: a product's Features tab.
curl -X PUT https://paymenthooks.com/api/v1/products/ph_pro_6512bd43d9caa6e02c990b0a82652dca/features \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{
"features": [
{ "featureId": "ph_fea_7d2a9c4e1b6f3a8d0c5e2b7f4a9d1c6e", "limitValue": 5000 },
{ "featureId": "ph_fea_0b4f8c2e6a1d5b9f3c7e1a5d9b3f7c2e", "limitValue": 3 },
{ "featureId": "ph_fea_1e5c9a3d7b2f6e0a4c8d2b6f1a5e9c3d" },
{ "featureId": "ph_fea_9c3e7a1d5f0b4e8c2a6d0f4b8e2c6a1d", "enabled": false }
]
}'
# 200 { "data": [ { "featureId": "ph_fea_7d2a9c4e1b6f3a8d0c5e2b7f4a9d1c6e", "key": "api_calls", "enabled": true, "limitValue": 5000, "displayOrder": 0, ... }, ... ] }| Field | Type | Description |
|---|---|---|
featureId | string | One of your active features. A feature already on the product may stay after it is archived; an archived feature cannot be added. Listed once. |
enabled | booleanDefault: | Whether the plan includes it. false keeps the row (useful for plan comparisons) but grants nothing. |
limitValue | integer | nullDefault: | quantity and metered: the maximum, 0 to 2,147,483,647; null = unlimited. boolean features take no maximum. Ignored when enabled is false. |
displayOrder | integerDefault: | Order in "What's included" (0 to 10,000). |
At most 50 features per product. The Node SDK does not wrap the feature endpoints yet; call them over HTTPS as shown.
What's included
The product's enabled features are shown to customers as What's included, in displayOrder, with the same wording everywhere: Priority support, 3 projects, Unlimited projects, 5,000 calls / month, followed by the price's overage terms when it bills overage (then $1.00 per 1,000 calls).
- Subscription checkout: under the plan summary. When the product has no enabled features the section is not shown. See Checkout Sessions.
- Subscription emails:
subscription_confirmed(a subscription starts) andsubscription_plan_changedlist the features the subscription grants as "What's included", one line each (for exampleAPI calls: Metered, 5,000 calls / month), with the customer's overrides applied. A trialing subscription adds a note that usage above a limit is not billed until the first billing date. When the plan has no enabled features, the variant without the section is sent instead:subscription_confirmed_no_featuresorsubscription_plan_changed_no_features.
Customer entitlements
A feature (boolean, quantity or metered) is defined once per merchant; a product says whether it includes it and its maximum (limitValue, null= unlimited). A subscription is snapshotted with the terms it runs under, so a catalogue edit applies from each subscription's next period. A customer's entitlement resolves as: customer override, then the source subscription's snapshot (the price's overage over the product feature), then not granted. One subscription is the source per feature: the earliest-started one in active, trialing or past_due(past due keeps access by default); its base price and add-ons add up, and unlimited wins.
| Field | Type | Description |
|---|---|---|
GET /customers/{id}/entitlements | entitlements:read | Every feature the customer is granted: key, type, enabled, limit (null = unlimited), used, remaining, policy, overageUnits, estimatedOverageLocalCurrencyAmount / estimatedOverageAmountUsdCents, resetsAt, source (product, price, customer_override). |
GET /customers/{id}/entitlements/{key} | entitlements:read | One feature. Not granted answers 200 with enabled: false; an unknown key answers 404. |
POST /customers/{id}/entitlements/{key}/check | entitlements:read | Body { quantity } (default 1). Read-only and exact: { allowed, remaining, wouldBeOverage, reason, used, limit, policy, enforced }. policy is the price's (restrict, allow, bill); enforced says whether PaymentHooks itself refuses what the check disallows. Nothing is reserved. |
PUT /customers/{id}/feature-usage/{key} | entitlements:write | Quantity features: { quantity } in use now. Going up past the maximum answers 409 ENTITLEMENT_LIMIT_REACHED unless the price's policy is allow; going down always succeeds. Supports Idempotency-Key. |
GET/PUT/DELETE /customers/{id}/feature-overrides/{key} | entitlements:write | A negotiated exception for one customer (audited). GET /customers/{id}/feature-overrides lists them. |
GET/PUT /prices/{id}/feature-overage | products:write | Overage per quantity/metered feature of the price's product (whole list): restrict, allow or bill. |
GET /subscriptions/{id}/features | entitlements:read | The subscription's Features card: usage, policy, estimated overage, reset date, adjustments, features covered by an earlier subscription. |
GET/PATCH /merchant/entitlement-settings | entitlements:write | pastDueKeepsAccess, notifyCustomer, alertThresholds, upgradeAllowance, billOverageOnCancel. The removed mode answers 400. |
curl https://paymenthooks.com/api/v1/customers/ph_cus_8f14e45fceea167a5a36dedd4bea2543/entitlements/api_calls/check \
-H "Authorization: Bearer phk_live_..." \
-H "Content-Type: application/json" \
-d '{ "quantity": 1 }'
# { "data": { "allowed": true, "remaining": 1200, "wouldBeOverage": false, "policy": "bill", "enforced": true, ... } }
curl -X PUT https://paymenthooks.com/api/v1/customers/ph_cus_8f14e45fceea167a5a36dedd4bea2543/feature-usage/projects \
-H "Authorization: Bearer phk_live_..." -H "Idempotency-Key: proj-42" \
-H "Content-Type: application/json" -d '{ "quantity": 3 }'Overage and exact usage
Overage belongs to the price (PUT /prices/{id}/feature-overage). restrict (the default) refuses usage above the maximum; allow records it, with alerts and webhooks, and never refuses or charges it; bill (metered features only) charges itemOverageUnitLocalCurrencyAmount per overagePackageSizeunits in the price's currency, up to overageCap units above the maximum. A feature whose meter a metered price already bills cannot bill overage (409 FEATURE_METER_BILLED_BY_PRICE). Each accepted meter event updates the usage ledger in one conditional statement in the same transaction as the event, so two events at the limit cannot both pass. An event the price's policy refuses answers 409 ENTITLEMENT_LIMIT_REACHED or ENTITLEMENT_OVERAGE_CAP_REACHED and is not stored. An event for a customer without a granting subscription is stored as a meter reading and counts against no feature; a quantity in use without one answers 409 NO_ENTITLEMENT. An event dated in a closed period becomes an adjustment billed on the next invoice.
| Field | Type | Description |
|---|---|---|
featureId | string | A quantity or metered feature on the price's product. |
policy | string | restrict (refuse above the maximum; the default), allow (record and alert, never refuse or charge) or bill (metered features only). |
itemOverageUnitLocalCurrencyAmount | integer | bill: price per package in the price's currency, smallest unit (from 1). The USD cents are derived at the price's itemUsdToLocalCurrencyRate. |
overagePackageSize | integerDefault: | Units per package (from 1). 1,500 units over with a package of 1,000 bills 2 packages. |
overageCap | integer | nullDefault: | bill: units allowed above the maximum; usage beyond is refused (409 ENTITLEMENT_OVERAGE_CAP_REACHED). |
| Field | Type | Description |
|---|---|---|
enabled | boolean | null | Include or exclude the feature for this customer; null keeps the plan's. |
limitValue | integer | null | A different maximum; null keeps the plan's. |
unlimited | booleanDefault: | No maximum for this customer (not with limitValue). |
policy | string | null | restrict or bill (metered; billing uses the price's overage terms). |
reason | string | Why (3-500 characters), kept in the audit log. |
expiresAt | string | null | ISO 8601 date after which the plan's terms apply again. |
At renewal the period closes and each billed feature adds one invoice line with kind: "overage", featureKeyand the period, used, limit, packages and unit stored on the line, taxed with the subscription's tax snapshot. A cancelled subscription gets a final overage invoice (billOverageOnCancel, default on). Credit notes can credit an overage line with lineItems[].invoiceLineIndex. Overage is reported as usage revenue, not MRR. Trials get the full maximums; a billing price refuses overage until the trial ends.
Entitlement webhooks
entitlements.active_entitlement_summary.updated is sent when a customer's features or limits change. Usage events (usage_threshold.reached, limit_reached, overage.started, overage_cap.reached, usage.rejected, usage_period.closed) are sent once per customer, feature, period and event, with one entitlement_usage object: feature, limit, used, remaining, percent, period and an overage object with Stripe-style money (unit_amount and lowercase currency, plus amount_usd_cents and usd_to_local_currency_rate). See Webhook events.
Usage alert emails
When a customer's usage crosses one of your alertThresholds (PATCH /merchant/entitlement-settings), PaymentHooks emails it once per customer, feature, period and threshold. Each email states the used and allowed amounts, the period, and what happens next under the price's policy: refused, allowed without charge, or billed as overage on the next invoice.
| Field | Type | Description |
|---|---|---|
feature_usage_alert_merchant | to you | Sent when a customer's usage of a quantity or metered feature crosses one of alertThresholds (default 75, 90 and 100%) while the mode is report or enforce. Goes to your account email and team members who can see settings. Controlled by Plan usage under Settings > Notifications, except that reaching 100% is always sent. |
feature_usage_alert_customer | to the customer | The same alert, branded as your business, with a link to the customer's billing page. Sent only when notifyCustomer is true; controlled by Subscription updates under Settings > Notifications. |
SDK
await ph.subscriptionItems.create("ph_sub_aab3238922bcc25a6f606eb525ffdc56", { priceId: "ph_pri_b6d767d2f8ed5d21a44b0e5886680cb9", quantity: 3 });
await ph.subscriptionItems.update("ph_sub_aab3238922bcc25a6f606eb525ffdc56", "ph_sit_37693cfc748049e45d87b8c7d8b9aacd", { quantity: 5 });
await ph.subscriptionItems.addInvoiceItem("ph_sub_aab3238922bcc25a6f606eb525ffdc56", { priceId: "ph_pri_1ff1de774005f8da13f42943881c655f" });
const upcoming = await ph.subscriptions.upcomingInvoice("ph_sub_aab3238922bcc25a6f606eb525ffdc56");
const usage = await ph.meters.usage("ph_mtr_4b8e2d6a0c3f7b1e5d9a2c6f0b4e8d3a");