Skip to content
Sonic AI

Usage templates: a contract with a file you haven't seen yet

A usage template maps each customer's usage file to billable events. The three jobs it does, why nothing bills until you process it, and choosing the key.

Lokesh Mahala

Lokesh Mahala, CEO & Co-founder

· Updated · 4 min read

Loose file sheets passing through a template frame and coming out as a neat row of blue events.
On this page

A usage template is a saved mapping from a customer's usage export to billable events: which customer each row belongs to, what it measures, and whether you have seen it before. You build it once on a sample file, and it has to keep working on every later file, so build it for the messiest export you might get.

The first usage file a customer sends you is a demo. The fortieth one is the job. Somewhere between the two, column order shifts, someone adds a currency field, a vendor starts sending corrections with the same timestamp as the original row, and a mapping hard-coded against file one quietly stops matching file forty.

That drift is why a template has to be built defensively, not just correctly for today's sample. The same template rules apply whether usage arrives as an upload or as a scheduled usage sync from your database, and this is the step in usage-based billing where most invoice errors start.

The three jobs of a usage template, and how each one fails

Turning a raw row into a billable event means answering three questions, and each one has its own failure mode if you get it wrong:

Which customer does this row belong to? Get this wrong and you bill the right amount to the wrong account. It's a matching problem, usually caught fast because the wrong customer complains.

What does this row actually measure? Get this wrong, with a unit conversion off by a factor or a currency field misread as a count, and each invoice downstream is wrong by the same silent multiplier. That one is caught slowly, usually at renewal, when someone finally reconciles a year of invoices against a year of raw exports.

Have I seen this exact row before? Get this wrong and a routine re-run (a retry after a timeout, a corrected re-export, an hourly sync that overlaps its own window) turns into a duplicate charge. This is the one that costs you a customer relationship, not just an adjustment invoice.

Most billing incidents trace back to the third question, because it's the one people assume the platform handles automatically. It doesn't, on purpose.

Why a usage file shouldn't bill until you process it

The tempting design is to stage and validate a file the moment it's uploaded, so the operator sees results instantly. That convenience is exactly how partial, wrong, or duplicate data gets a foothold: a sample uploaded to check column headers gets treated as a live run, and now there's billable-looking data sitting in a system that assumes anything present is meant to be there.

Sonic keeps the boundary explicit instead. Attaching or previewing a file changes nothing on its own. A separate, deliberate action, the Process step, turns a mapping into a validated, billable pipeline. Until that happens, nothing downstream reads the file as real.

The cost is one extra click. The benefit is that "I was just looking at the file" can never become "I accidentally billed the file."

How to choose the idempotency key

The idempotency key is the set of columns that makes a row unique. You set it, because that answer is different for every vendor, and Sonic applies exactly the key you choose. A payments processor's transaction ID is a safe key. A telecom call detail record's (account, call start time) pair is usually safe. "Customer plus calendar day" is safe only if the vendor never sends more than one correction for the same day, a promise most vendors don't keep.

The wrong key doesn't fail loudly. It fails the third or fourth time you re-run the same file, when a correction with a new value but the same "unique" key is either silently dropped (undercounting) or silently duplicated (overcounting). By then the file that exposed the bug has already been reprocessed and archived. Idempotency as a product feature goes deeper on why.

What happens to billed usage when you change a mapping

Templates get edited often as vendors change their export format. The rule that matters: changing a mapping changes how future files are read. It does not reach back and reinterpret events you already billed.

That's a deliberate asymmetry. A mapping fix can't retroactively turn last month's correct invoice into this month's "corrected" one, which is the same rule that keeps an issued invoice frozen once it's out the door.

Watch out for: a key that only works on the sample file

  • Test a new or changed mapping on a small window before pointing it at an hourly sync. A wrong transform scales as fast as your sync frequency.
  • A "customer + date" key is a bet that the vendor never sends same-day corrections. Most vendors eventually do.
  • Late-arriving usage lands on the next open invoice, not the one already sent. Immutability applies to usage lines the same way it applies to everything else.
  • Seat data is not usage data wearing a different hat. Seat ingestion adds confirmation windows and snapshot semantics that don't transfer from a usage key design.
  • The sample file you tuned the mapping against is not the file you'll get in production. Build the key for the messiest plausible export, not the clean one you were handed for the demo.
Lokesh Mahala

Written by

Lokesh Mahala

CEO & Co-founder, Sonic AI · LinkedIn

Lokesh is the Cofounder & CEO of Sonic AI. Before starting Sonic, Lokesh was an engineer at Stripe for 4 years building Stripe's Revenue and Finance Automation suite. He was a founding engineer at Recko (acquired by Stripe in 2021) where he built reconciliation solutions for B2C companies. He completed his bachelors from IIT Roorkee.

FAQ

What columns does a usage file need for billing?

At minimum: something that identifies the customer, a timestamp, the meter or product being measured, and a quantity. Add a column, or a set of columns, that makes each row unique, so a re-run can be recognised as a repeat. Everything else, such as region or plan, is optional unless your pricing depends on it.

What happens if the same usage file is uploaded twice?

With a good idempotency key, nothing. Rows already ingested are recognised by their key and skipped, so the second upload creates no new events. With a weak key, such as customer plus day, corrected rows can be dropped or duplicated. That's why the key should be built from the columns the vendor guarantees are unique.

Can I change a usage template after invoices have gone out?

Yes. Vendors change their export formats, so templates get edited often. A change affects how future files are read and does not reinterpret usage that has already been billed. If last month's numbers were wrong, correct them with a credit note or on the next open invoice, not by re-reading the old file.

How do seat counts get in, compared with usage?

Usage arrives as a file upload or a scheduled sync from your database, and a template maps it to events. Seats are different: they come in as daily snapshots of how many seats each customer had, compared with the balance on record, and an event is written only when the count changes.

See Sonic run on one of your contracts.

A 30-minute call with the team, using your own contract.

Book a demo