Skip to main content
This page covers the API. Meters and the plans that bill them are set up in the app. For how plans price, see Plans explained.
Some plans bill for what a customer uses, not only for a fixed fee. Your platform reports the usage as events. Saasybill totals them at the end of each billing period, prices the total, and raises the invoice in Xero.

How it works

A meter is what is counted, such as api_calls or storage_gb. A plan chooses which meters it bills and prices each one on its own. A subscription on that plan is billed for the meters it uses.
1

Find the meter

Each plan lists the meters it bills in meters. Read the meter_code there. See Find the meter.
2

Report usage

Send events to POST /v1/usage_events as usage happens. Each names a subscription, a meter, a quantity and a time. Nothing is billed yet.
3

The period closes

At the subscription’s renewal date, Saasybill totals each meter’s events for the period that just ended and prices the total with the plan’s pricing for that meter.
4

Saasybill invoices it

The usage is billed in arrears, as lines on an invoice in Xero. Each line is a usage line.
A plan can bill a fixed fee, usage, or both.
Usage is always billed after the period, and the recurring fee always before it. You don’t choose the timing.

Before you report usage

You need three things.
  1. A key with the usage:write scope. See Authentication. A key that only reports usage needs no other scope.
  2. The subscription’s id. Save it when you create the subscription. Events name the subscription by its Saasybill id, not by a customer code.
  3. The meter. Meters are created in the app and can’t be created through the API.

Find the meter

List plans and read each plan’s meters. Each entry has a meter (the Saasybill id) and a meter_code (the meter’s ID as it appears in the app).
An event names the meter with either meter or meter_code. Send exactly one. A meter_code is matched exactly, so API_Calls and api_calls are two different meters.
Cache the meter codes with the rest of your catalogue. They only change when someone edits a meter in the app.

Report usage

POST /v1/usage_events takes a batch of up to 100 events.

Event fields

Quantities can be fractions, such as 12.5 gigabytes. Send a string if your language can’t represent the number exactly.

What a timestamp can be

An event is sorted into a billing period by its timestamp, not by when it arrives.
  • It can’t be more than five minutes in the future. An event dated further ahead is usually a unit mistake, such as milliseconds sent as seconds.
  • It can’t be before the subscription started, or after it ended.
  • It can be any age otherwise. See Late usage.

Check every result

Reporting usage can partly succeed, so a 2xx doesn’t mean every event was stored. The body is a usage event batch. It counts what happened and gives one result per event, in the order you sent them.
If you ignore the body, you lose rejected events silently. Always read rejected. Branch on error.code, never on error.message.
A rejected event is not stored. Fix the cause and send it again.

Rejection codes


Resend safely

The event_id is what makes a resend safe. If a request times out, send the same batch again. Use an id from your own system that is the same on every attempt, such as your meter reading’s id. Two quantities that look the same, like 12.5 and 12.50, are the same quantity.
An Idempotency-Key is accepted but optional here, because every event carries its own event_id.

How usage is priced

At the end of the period, Saasybill totals each meter’s events and prices the total with the plan’s pricing for that meter.
  1. Total. A meter’s events are summed over the period, which runs from the subscription’s start date to its renewal date, in the subscription’s timezone.
  2. Minimum. The period bills the larger of the total and the meter’s minimum, so a period with no events still bills the minimum.
  3. Round up. The result is rounded up to whole units, so a customer is never billed for less than they used.
  4. Price. The whole-unit quantity is priced by the meter’s pricing_model.
  5. Discount. The subscription’s discount comes off the result.
For example, 14,000 calls on a per_unit meter with 10,000 included at 0.0200 bill 4,000 × 0.02 = 80.00. Rates can have up to four decimal places, because a unit is often worth less than a cent. No usage is no charge under every model, and a meter that prices to nothing gets no line. A period where no meter prices to anything raises no invoice.

Meter minimums

A meter can have a minimum: the least a period bills for it. The plan sets it in meters[].minimum_units. A subscription can raise it for itself, but never lower it. Set it when you create the subscription, with meter_minimums. Name each meter by meter or meter_code.
The 422 names the field, such as meter_minimums.0.meter. The minimum in force for each meter is in the subscription’s meters, as minimum_units, beside the plan’s own in plan_minimum_units.

Usage on an invoice

Each meter that prices to something becomes one line on the invoice. Read it with GET /v1/invoices.
Depending on the organisation’s invoicing settings, the usage is either lines on the renewal invoice or an invoice of its own. Either way, the invoice follows the organisation’s usual rules for status and approval, and it reaches you through the same webhooks as any other invoice.
The organisation can set a usage grace period of 0 to 28 days. It delays the usage invoice after the period closes, for senders that can only report once a period is over. Events reported during the grace days are on time.
Once an organisation has defined a meter, it must map a Usage Revenue account in Xero. Until it does, creating a subscription or changing units answers 409 xero_accounts_not_mapped, whatever plan is sold.

Late usage

An event for a period that has already been invoiced is late. Saasybill accepts it and doesn’t reject it. The response doesn’t flag it as late. In the app, the subscription asks a person what to do with late usage that costs more:
  • Amend the usage invoice, while it can still be changed in Xero.
  • Raise a new invoice for the late usage.
  • Add it to the next invoice.
  • Ignore it, which bills nothing.
If nobody acts, the late usage is added to the next renewal invoice, so nothing is lost. Late usage is priced at the marginal price: the price of the new total less what was already billed. A volume meter can price lower when late usage takes the total into a cheaper band. Saasybill then credits the customer automatically with a credit note, which you can read with GET /v1/credit_notes.
If your system can only report once a period is over, ask the organisation to set a usage grace period, so each period’s usage arrives on time and not late.

Usage on a subscription

A subscription shows two figures for its meters, and keeps them apart. usage_value is 0.0000 until a period has closed. It is priced at the plan’s current meter prices, so treat it as a forecast and not as what was billed.

Ending a subscription

A subscription on a plan that bills meters gets a final usage invoice for the usage up to its end date.
  • End at period end. The final period closes at the end date, and its usage is invoiced after any grace period.
  • End now. The usage so far is closed at that moment. Send invoice_usage_now: true to raise the invoice at once, and not after the grace period. See End and restore.
Events dated after the end are rejected as after_subscription_end. Restoring a subscription drops a closing period that hasn’t been invoiced, so nothing is billed twice.

Things to know

The API takes usage events and doesn’t return them. Keep your own record of what you sent. The subscription’s usage_value and the usage lines on its invoices show what Saasybill billed.
You can read a plan’s meters, but you can’t create or edit a meter or its pricing. A plan’s meters and prices also lock once any subscription uses the plan.
A plan with no recurring fee has no units, and a unit change on it is refused. Usage is reported as events, not set as a total.
With cpi_enabled, the rates of a plan’s meters rise by CPI at each annual renewal. Usage is billed in arrears, so the year gone by is priced at the rate in force during it. Included units, tier boundaries and meter minimums don’t change.
Report events with a test key, then advance the sandbox’s clock past the end of the period. See Testing.