Platform services
$meter
$meter records what an app decided to charge for (a send, a
byte, a seat) as readings nothing can take back, so a bill can be read from them months later.
Only server code meters: a $-method or a service. The meter on
this page is the docs', shared by everybody who opens it.
Count what happened
$meter.inc(bucket, amount) adds to a bucket, named by the
properties you give it. Here a service counts one sent email for an account each time it runs.
// services/meterdemo.mjs
export async function sendEmail({ account }) {
// …send the email…
await $meter.inc({ meter: 'demo-email', account })
}
// blocks/metering.mjs
async $sendEmail() {
await $meterdemo.sendEmail({ account: 'acc-1' })
}
Read it back, by day
$meter.report(bucket, window) answers a series of totals, one per
hour, day or month, and the total over the window: the last seven days of sends below.
const answer = await $meter.report(
{ meter: 'demo-email', account: 'acc-1' },
{ from: '2026-10-09', to: '2026-10-16', resolution: 'day' },
)
answer.series // [{ period, total }, …]
answer.total
| 2026-10-09 | 0 |
| 2026-10-10 | 0 |
| 2026-10-11 | 0 |
| 2026-10-12 | 0 |
| 2026-10-13 | 0 |
| 2026-10-14 | 0 |
| 2026-10-15 | 0 |
| total | 0 |