Skip to main content
Every dollar you bill a customer has a dollar (or a fraction of one) of cost behind it — an LLM call, a render farm, a transactional email. Macropay lets you record that cost on the same event stream you already use for usage-based billing, so spend and revenue live side by side instead of in two disconnected systems. You do this by attaching a reserved _cost tag to an event’s metadata when you ingest it. From there, costs roll up through the Metrics API right next to revenue — giving you margin, not just turnover.
Because Macropay is your Merchant of Record, the revenue side of this picture is already net of sales tax and VAT — we remit those globally on your behalf. Pairing that with cost events means the margin you see is genuinely yours to keep.

How it works

  1. You ingest an event through the Event Ingestion API as usual.
  2. You add a _cost object inside that event’s metadata.
  3. Macropay aggregates the cost and exposes it through the Metrics API alongside billed revenue.
The cost tag is purely additive. It never changes how the event is metered or billed — it simply records what the event cost you so you can reason about profitability.

The _cost tag

Add _cost to any event’s metadata. Here is the minimal shape:

Fields

amount is in cents, not dollars. A whole number is whole cents, and decimals go sub-cent. So 100 = 1.00,0.5=halfacent(1.00, `0.5` = half a cent (0.005), and 0.001 = one hundredth of a cent ($0.00001). Mixing up cents and dollars is the most common Cost Insights mistake — double-check the magnitude.

What to track

_cost is deliberately generic: anything that costs you money per unit of activity is fair game. Three common patterns:
The headline use case. Record what each model call cost, attributed to the customer who triggered it. Stash token counts in metadata too, so you can later slice cost by model and prompt size.
TypeScript
Routing model traffic through the Macropay AI proxy (POST /ai/v1/chat/completions) captures token cost for you automatically — no manual rate math, no _cost plumbing. Use manual _cost tagging when you call providers directly or need to fold in costs the proxy can’t see.

Why margin matters for agents

If you bill autonomous agents, cost events are half of a profitability equation. The other half is what the agent earned: with the Signals API you certify the value an agent delivered, and Macropay computes agentic margin — billed revenue versus the AI cost (COGS) behind it, per agent. Tag every model call, tool invocation, and downstream service with _cost, and that COGS figure becomes real instead of a guess. An agent that bills well but burns more in tokens than it earns shows up immediately, before it quietly erodes your margin.

Practical tips

Record the cost on the same code path that incurs it — right after the API call returns. Real-time ingestion keeps your margin metrics live and avoids batch reconciliation drift.
TypeScript
The 12-decimal precision exists so a single token or a single API hit never rounds to zero. At scale, those fractions are your real cost.
0.000125 cents is $0.00000125 — preserved exactly.
A bare number tells you how much; surrounding metadata tells you why. Tag the model, feature, or workload so you can group spend by driver later.