Schema decisions made at the beginning of a billing implementation are among the hardest to change later. Adding a field to a schema is a migration. Removing one requires understanding every downstream consumer. Changing the semantics of an existing field (say, deciding that quantity now means "weighted units" instead of "raw call count") requires recomputing historical aggregates or accepting that pre-change and post-change events are measured differently. In practice, early schema decisions become permanent faster than engineers expect, because billing data retention requirements mean you are living with the original schema for years.
This post covers the specific fields that seem optional at launch, appear in support tickets within six months, and take a painful backfill to add retroactively. Get these in the schema before you go to production.
The Required Fields That Everyone Includes
There is a core set that every billing event schema includes, because without them the event is not usable for billing at all:
event_idoridempotency_key: unique identifier for this specific event occurrencecustomer_id: which account generated this eventevent_type: what kind of operation this represents, for pricing rule matchingquantity: how much of the event type occurred (usually 1 for discrete events, a count for batched)timestamp: when the event occurred, for billing period assignment
These get included because the billing system literally cannot function without them. What is less obvious is the set of fields that the billing system can technically function without, but that turn out to be necessary for correct operation, customer trust, and dispute resolution.
The Metadata Field Is Not Optional
A freeform metadata object (or named fields within a metadata block) on every billing event is the mechanism by which you preserve the context that turns a count into a verifiable record. Without it, your billing events answer "how many" but not "what."
For AI application billing, the metadata that matters most is the model identifier, input and output token counts, the prompt or input hash (not the full content, just enough to identify the call), and any version or variant identifier for the AI feature that generated the event. When a customer disputes a bill and asks why their token usage was higher this month, you need to be able to answer with specifics. "Your model upgrade to GPT-4o from GPT-4 Turbo increased average input token counts by approximately 18 percent over the billing period" is a verifiable, specific answer. "We recorded more usage this month" is not.
The metadata field should be treated as an append-only audit log component, not a generic bag of properties. Define the fields you will use in your first version, make them stable, and add new fields additively rather than replacing old ones.
workflow_id and trace_id: The Attribution Fields
As covered in the multi-agent attribution article, workflow_id and trace_id are what allow you to reconstruct which pipeline execution generated which events. These feel like nice-to-have debugging fields when you launch with a single-agent product. They become required fields the first time you add a workflow with sub-agents, because without them there is no way to break down a customer's bill by the features or workflows they used.
The cost of adding these fields retroactively is not just the schema migration. It is that every event recorded before the migration cannot be attributed to a workflow, so historical billing data has a different granularity than post-migration data. If you added multi-agent features at month four and added workflow attribution at month six, you have two months of events that cannot be analyzed by workflow. Depending on your customer reporting requirements, that gap may need to be explicitly communicated.
Add these fields in the initial schema with optional values. In single-agent scenarios, pass null or an empty string. When you add multi-agent workflows later, populate them. The query infrastructure to use these fields can be added incrementally. The fields themselves need to be present from the start to avoid the retroactive gap.
ingested_at vs. occurred_at: Two Timestamps You Need
Events in distributed systems arrive out of order. An event that occurred at 11:58 PM may arrive at the metering endpoint at 12:02 AM the next day. If your billing period closes at midnight and you use arrival time as the event timestamp, that event falls in the wrong billing period. If you use the client-reported occurrence time, you are trusting the client's clock, which may be wrong.
The practical solution is two timestamps: occurred_at is the client-reported time when the event happened. ingested_at is the server-recorded time when the event arrived. For billing period assignment, use occurred_at with a grace window: events that arrive within N minutes after period close and report occurred_at within the prior period are attributed to the prior period. Events that arrive more than N minutes late are attributed to the arrival period.
This schema requires both timestamps to implement correctly. If you only store ingested_at, you cannot implement the grace window retroactively because you do not know when the event actually occurred. Include both timestamps from the start, even if your first billing period boundary logic is simpler than this.
environment: The Field That Prevents Test Billing
Every AI application generates billing events in development and staging as well as production. Without an environment field on every event, filtering test events from production billing requires either separate API keys (which creates operational complexity) or post-hoc logic to infer environment from other fields (which is fragile).
A simple enum field with values like production, staging, and development lets your billing infrastructure filter non-production events at ingest, log them for debugging purposes, and exclude them from the billing ledger without any additional complexity. Without it, you will filter by API key or by some pattern in the customer_id that identifies test accounts. Those approaches work but require convention enforcement across everyone who writes events. An explicit field in the schema requires no convention.
event_version: For Schema Evolution
As your product adds event types and your pricing model evolves, your event schema will change. An event_version field records which version of the schema produced this event. When you need to process historical events with different code paths depending on which schema version they were generated under, this field makes that possible.
Without it, you are left inferring schema version from field presence, which is fragile as schemas change. The field costs you nothing to add at the start and saves the debugging time of figuring out why events from six months ago do not parse correctly under the current schema.
What This Looks Like as a Complete Event
A billing event schema that includes all of the above ends up looking like this for a model completion event:
{
"idempotency_key": "evt_wf_3301_step_2_c001",
"customer_id": "cust_northshore_ai",
"event_type": "model.completion",
"event_version": "v2",
"environment": "production",
"quantity": 1,
"occurred_at": "2026-03-22T14:23:11.042Z",
"workflow_id": "wf_invoice_extract_20260322",
"trace_id": "trc_3301",
"agent_id": "agt_extraction_01",
"parent_agent_id": null,
"metadata": {
"model": "claude-3-5-sonnet",
"input_tokens": 2100,
"output_tokens": 340,
"feature": "invoice_extraction"
}
}
This is not a large payload. The billing overhead per event is under 400 bytes. The fields that seem redundant when you are building a single-agent MVP are the ones that make the billing system verifiable, attributable, and dispute-resistant once you are operating at production scale with real customers reviewing their bills.