Skip to navigation

Graduated pricing with an annual minimum

Brieflens runs an agent that reviews contracts and flags risky clauses. It charges per page reviewed, cheaper at volume: 12¢ a page for the first 50,000 pages a month, 8¢ up to 200,000, and 5¢ above that. Its customer Umbrella Legal, a law firm, signs a $120,000 annual minimum with 10% off list, and wants its usage split by practice group: litigation, M&A and employment.

This example uses:

The calls below show only the request body. Every request also sends the headers listed under request headers: Authorization, Paid-Version, the Paid-Beta opt-in each endpoint requires (for example orders=v1 for orders and events=v1 for events), and an Idempotency-Key on writes so you can retry them safely.

Money amounts on prices are decimal strings in cents ("12" is 12¢). Amounts on commits are integers in cents (12000000 is $120,000.00).

Setup

These calls run once, when Brieflens sets up its catalog.

Create a product for document review:

POST /v1/products
{
"externalId": "doc_review",
"name": "Document review"
}

Create a meter that sums the pages field of every document.reviewed event:

POST /v1/meters
{
"key": "pages_reviewed",
"name": "Pages reviewed",
"eventNames": ["document.reviewed"],
"measure": {
"type": "events",
"events": {
"aggregation": {
"type": "sum",
"sum": { "path": "payload.pages" }
},
"unit": "page"
}
}
}

Create a usage price on that meter with graduated tiers. Each tier is charged at its own rate, and the tiers reset every billing period (tierScope defaults to billingPeriod):

POST /v1/prices
{
"product": "doc_review",
"currency": "usd",
"type": "usage",
"usage": {
"meter": "pages_reviewed",
"pricing": {
"type": "graduated",
"graduated": {
"tiers": [
{ "upTo": "50000", "unitAmount": "12" },
{ "upTo": "200000", "unitAmount": "8" },
{ "upTo": null, "unitAmount": "5" }
]
}
}
}
}

The response returns the price’s ID, prc_4Lm9Tz in this example.

Create the customer:

POST /v1/customers
{
"externalId": "umbrella-legal",
"name": "Umbrella Legal",
"currency": "usd",
"taxIds": [{ "type": "gbVat", "value": "GB123456789" }]
}

Create an order for the 2027 term. It carries the page price, Net 45 payment terms, the 10% discount in negotiatedPricing and the $120,000 minimum in commits. Both are created with the order and apply to this order only:

POST /v1/orders
{
"customer": "umbrella-legal",
"externalId": "umbrella-legal-2027",
"startsAt": "2027-01-01T00:00:00Z",
"endsAt": "2028-01-01T00:00:00Z",
"billingCycle": { "interval": "month" },
"paymentTerms": "net45",
"lines": [
{ "type": "price", "price": { "price": "prc_4Lm9Tz" } }
],
"negotiatedPricing": [
{
"key": "enterprise_discount",
"type": "discount",
"discount": {
"type": "percentage",
"percentage": { "percentOff": "10" }
},
"target": {
"type": "product",
"product": { "product": "doc_review" }
}
}
],
"commits": [
{
"type": "invoicedMinimum",
"name": "2027 minimum",
"amount": 12000000,
"currency": "usd",
"period": "term"
}
]
}

The discount has no startsAt or endsAt, so it lasts as long as the order. With period: "term", the minimum is measured once across the whole year rather than each month.

The order is created as a draft. Activate it to start billing; the request has no body:

Practice groups

Model the practice groups as customer units. Create the root unit for the firm first:

POST /v1/customers/umbrella-legal/units
{
"externalId": "umbrella-legal",
"name": "Umbrella Legal",
"kind": "firm"
}

Then one unit per practice group under it:

POST /v1/customers/umbrella-legal/units
{
"externalId": "litigation",
"parent": "umbrella-legal",
"name": "Litigation",
"kind": "practiceGroup"
}

And the same for m-and-a (M&A) and employment (Employment).

Units attribute usage; they don’t change pricing. The graduated tiers, the discount and the minimum all apply to the firm’s total pages, once.

Sending usage

Send an event for every document reviewed, naming the practice group in customerUnit. Use the document’s ID as the dedupeKey, so a retried send isn’t counted twice:

POST /v1/events
{
"eventName": "document.reviewed",
"customer": "umbrella-legal",
"customerUnit": "litigation",
"product": "doc_review",
"dedupeKey": "doc_8f2k1q",
"payload": { "pages": 42, "documentType": "nda" }
}

To send many documents at once, use create an event batch with up to 1,000 events.

The month

In January, Umbrella Legal’s lawyers review 180,000 pages. The tiers split them as follows, and the 10% discount comes off each tier:

TierPagesListAfter 10% off
First 50,000 at 12¢50,000$6,000.00$5,400.00
50,001 to 200,000 at 8¢130,000$10,400.00$9,360.00
Total180,000$16,400.00$14,760.00
  • Graduated: 50,000 × 12¢ = $6,000.00 and 130,000 × 8¢ = $10,400.00. No pages reach the 5¢ tier. In February the count starts again at the first tier.
  • Discount: 10% off $16,400.00 is $1,640.00, leaving $14,760.00 on the invoice.
  • Minimum: the $14,760.00 counts toward the $120,000 term minimum at the discounted price. Retrieve the commit (GET /v1/commits/cmt_3Rv8Wd) to see the running total in balance: after January, consumed is 1476000 and remaining is 10524000.

If Umbrella Legal’s spend for the year ends at $112,300.00, the closing invoice adds a $7,700.00 line for the shortfall ($120,000.00 − $112,300.00). At $120,000.00 or more, it adds nothing.

Reporting by practice group

List usage summaries with basis=invoice to get rows that match each invoice exactly. This basis reads the posted usage charges, so a late adjustment shows up on the invoice that carried it:

GET /v1/usage-summaries
?customer=umbrella-legal
&meters[]=pages_reviewed
&startsAt=2027-01-01T00:00:00Z
&endsAt=2028-01-01T00:00:00Z
&granularity=billingPeriod
&basis=invoice
&groupBy[]=customerUnit

Grouping by customerUnit splits the same pages and spend by practice group. In January the rows show litigation at 96,000 pages, M&A at 61,000 and employment at 23,000, which add up to the 180,000 pages and $14,760.00 on the invoice. To report on one practice group alone, pass customerUnit=litigation instead of grouping.