Source library / Guides

Per-Customer AI Cost Attribution

A practical guide to attributing AI agent cost by customer, step, model, and source before margins drift.

Short answer

Per-customer AI cost attribution means every agent cost event carries the customer that caused it. Once LLM and non-LLM usage share the same customer_id and step_name, a builder can see margin, heavy users, expensive steps, and billing-ready usage without spreadsheets.

Query paths
  • - How do I know what each AI customer costs?
  • - How do I split an OpenAI bill by tenant?
  • - How do I find customers with negative AI margins?

Attribution Model

The minimum useful model is customer_id plus step_name. Customer_id answers who caused the spend. Step_name answers what part of the agent produced it.

Model and source breakdowns then become filters, not primary accounting keys. This keeps cost reports aligned with billing and customer operations.

FieldPurposeExample
customer_idRevenue and margin owneracme-corp
step_nameOptimization targetretrieve_context
sourceCost categoryopenai or elevenlabs
metricUsage unittokens or characters

Where It Breaks

Provider dashboards break because they aggregate by account, not by your end customer. Observability traces help explain behavior, but they still need cost-shaped fields before they can become billing or margin infrastructure.

Billing-Ready Events

A billing-ready event does not need prompt text. It needs identity, source, usage, time, and status. That is enough to aggregate cost by customer and later apply the builder's customer pricing model.

FAQ
Should customer_id be an email address?

No. Use an opaque external ID, account ID, or tenant slug instead of personal data.

Can the same event support dashboards and billing?

Yes. The same cost-shaped usage event can power cost views, rules, and invoice drafts.

What is the first report to build?

Start with total cost by customer for the last 30 days, then add step and source breakdowns.

Related reading