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.
How it works
A meter is what is counted, such asapi_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.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.- A key with the
usage:writescope. See Authentication. A key that only reports usage needs no other scope. - The subscription’s id. Save it when you create the subscription. Events name the subscription by its Saasybill id, not by a customer code.
- 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’smeters. Each entry has a meter (the Saasybill id) and a meter_code (the meter’s ID as it appears in the app).
meter or meter_code. Send exactly one. A meter_code is matched exactly, so API_Calls and api_calls are two different meters.
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 itstimestamp, 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 a2xx 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.
Rejection codes
Resend safely
Theevent_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.- 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.
- Minimum. The period bills the larger of the total and the meter’s minimum, so a period with no events still bills the minimum.
- Round up. The result is rounded up to whole units, so a customer is never billed for less than they used.
- Price. The whole-unit quantity is priced by the meter’s
pricing_model. - 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 inmeters[].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 withGET /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.
GET /v1/credit_notes.
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: trueto raise the invoice at once, and not after the grace period. See End and restore.
after_subscription_end. Restoring a subscription drops a closing period that hasn’t been invoiced, so nothing is billed twice.
Things to know
Reported usage can't be read back
Reported usage can't be read back
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.Meters are read-only in the API
Meters are read-only in the API
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.Units don't apply to usage
Units don't apply to usage
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.
Usage is billed at the rates of the period it was used in
Usage is billed at the rates of the period it was used in
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.Test with a sandbox
Test with a sandbox
Report events with a test key, then advance the sandbox’s clock past the end of the period. See Testing.