Why pre-fund a balance?
Sometimes the meter needs to start in the green before a single dollar changes hands. A free trial that hands out 1,000 tokens, a launch promo that drops bonus API calls into early accounts, or an AI agent you want to let run a few tasks before billing kicks in — all of these are the same primitive: a credit balance that exists ahead of any purchase. Macropay models this with metered usage. You seed a customer’s meter with credits, then let normal usage draw it down. Because Macropay is the merchant of record, the moment that customer does convert to a paid order, sales tax and VAT are calculated and remitted for you — the pre-funded balance and the eventual invoice live in the same system. Common scenarios:The mechanic: a negative event on a Sum meter
A meter with Sum aggregation simply adds up the values of every event it matches. Usage events carry a positive value and push the total up; a credit grant carries a negative value and pushes it down. That sign convention is the whole trick: the running sum represents consumption, so a negative running sum means the customer has unused credit in reserve. Each real usage event nudges it back toward zero, and once it crosses zero, billable usage begins.Reading the balanceIngest
-1000 on a Sum meter and the meter total becomes -1000. As the customer consumes, the total climbs: -1000 → -700 → 0. While the total is negative, its absolute value is the credit still available.What you’ll need
- A meter using Sum aggregation (created below)
- A customer record — or your own
externalIdto reference one - A Macropay access token (
MACROPAY_ACCESS_TOKEN)
Step 1 — Create a Sum meter
The meter defines which events count and how they’re aggregated.1
Open the Meters list
In the dashboard sidebar, go to Products → Meters.
2
Configure the meter
Click Create Meter and set:
- Name — something descriptive, e.g.
API CallsorRender Minutes - Filter — match your usage events, e.g. event name equals
api_usage - Aggregation — choose Sum, then enter the property to total (e.g.
units)
3
Save it
Save the meter and keep the event name handy — your ingested events must match the filter.
Step 2 — Make sure the customer exists
You can grant credits to a Macropay customer ID or to your ownexternalId. Create the customer first if they aren’t in Macropay yet.
From the dashboard
1
Open Customers
Click Customers in the sidebar.
2
Add the customer
Click Add Customer and provide:
- Email (required)
- Name (optional)
- External ID — your own user ID, e.g.
user_8842(optional but recommended)
3
Save
Save and copy the Customer ID.
From the API
create-customer.ts
Step 3 — Grant the credits
Ingest a single event with a negative value. This is the sameevents.ingest call you’d use for real usage — only the sign differs.
By Macropay customer ID
grant-credits.ts
By your own external ID
grant-credits-external.ts
Step 4 — Confirm the balance
Read the customer’s meters back. A negativebalance means credits are still in reserve, so the credits remaining is Math.abs(balance).
check-balance.ts
How the balance moves
Once seeded, the meter behaves like any other — positive events are real usage that draws the reserve down:lifecycle.ts