Skip to main content
When the thing your customer pays for is time — compute seconds, a rendering job, an agent’s run duration — you need a clean way to measure how long an operation took and turn that number into a billable event. The Delta Time strategy does exactly that: start a timer, run your code, stop the timer, and the elapsed deltaTime is ingested to Macropay automatically. Because Macropay is your Merchant of Record, those metered events flow straight into the meter → metered price pipeline. We invoice in the customer’s currency, remit any applicable sales tax or VAT on your behalf, and stay the seller of record on the statement — you just emit the duration.

What you’ll need

  • A meter that aggregates an event named execution-time (or whatever name you choose) into a metered price.
  • A MACROPAY_ACCESS_TOKEN available to your server.
  • The ingestion package installed.

Bring your own clock

Timing is only as good as the clock you read it from. Rather than lock you into one source, the strategy takes a now-resolver — a function returning the current time — so you can pick the precision your billing model requires:
Prefer a monotonic source like performance.now() or process.hrtime for billing. Wall-clock time (Date.now()) can jump backward when the system clock is adjusted, producing a negative or inflated delta.

Meter an operation end-to-end

The strategy wraps your now-resolver and hands back a start() function. Calling start() opens a timer and returns a stop() function; calling stop() closes it and ingests the measured deltaTime.
Pass customerId when you build the client so each event is attributed to the right customer. The X-Macropay-Customer-Id header is just one convenient place to read it from — use whatever your app already has (a session, a JWT claim, a path param).

What gets ingested

When stop() fires, the strategy posts a single event. deltaTime is the elapsed value in whatever unit your now-resolver returns:
Your meter aggregates deltaTime across events and applies the metered price — so “0.002persecondoftranscoding"or"0.002 per second of transcoding" or "0.05 per minute of agent runtime” is just a meter definition, not custom billing code.

Billing agents by runtime

Delta Time pairs naturally with agent billing. If you charge for an autonomous agent by how long it works, wrap the agent’s execution in start() / stop() and attribute the duration to the agent’s customer. The elapsed time becomes an activity signal you can meter directly, while value receipts certify the outcome — time saved or revenue generated — on top of raw runtime.