New guide

Refine your pricing strategy with a complete guide to pricing economics for AI agents.

Get the guide
×

AI cost attribution: how to track LLM cost per customer (2026)

How to attribute AI spend to each customer, feature, and agent, allocate the shared costs you can't trace, and turn cost per customer into margin per customer.

AI cost attribution: how to track LLM cost per customer (2026)

Your model provider's invoice says you spent $40,000 last month. It doesn't say which customers, features, or agents caused that spend, and nobody on your team can say either. One account could be costing you $9,000 a month on a plan that pays $3,000, and the invoice will never show it.

AI cost attribution is how you find out. It ties every model call and token back to the customer and feature behind it, so AI spend reads like the rest of your business. Managing that spend is now standard work: in the FinOps Foundation's State of FinOps 2026, 98% of practitioners said they manage AI spend, up from 63% a year earlier. Seeing it clearly is another matter. KPMG's Q2 2026 AI Pulse survey found that only 26% of organizations have full, real-time visibility into what their AI systems cost to operate.

This guide gives you a working method: how to attribute AI cost to each customer, allocate the shared costs you can't trace, and see margin per customer.

What is AI cost attribution?

AI cost attribution is the process of linking each model call, tool call, and token to the customer, feature, agent, and model that caused it. The result is AI spend measured per unit of your business, instead of one total on a provider invoice.

It matters for three decisions:

  • Pricing. You can't set a price, a credit rate, or a plan allowance that covers cost until you know what each customer costs to serve.
  • Finding unprofitable customers. Two accounts on the same plan can cost very different amounts. Attribution shows you which one is the problem.
  • Enforcing budgets. Spend caps and per-team budgets only work when cost is tracked at the customer and feature level.

The stakes are higher than in traditional software. Bessemer Venture Partners' AI pricing and monetization playbook puts gross margins for AI companies at 50-60%, against 80-90% for SaaS. When model cost takes that much of every dollar, a handful of expensive customers can move your company's margin, and you need cost per customer to see them.

AI cost attribution vs LLM observability vs cost reporting

Three kinds of tooling look at the same AI spend, and each answers a different question.

Cost reportingLLM observabilityAI cost attribution
Question it answersHow much did we spend?What happened inside this request?Who and what caused the spend?
Main viewTotal spend by provider and monthTraces, latency, tokens per requestSpend by customer, feature, and agent
Main usersFinanceEngineeringFinance, product, and pricing
Connects to revenueNoNoYes, when joined to billing

Attribution reuses observability data. The token counts and model names in your traces are the raw material. What attribution adds is business IDs, such as customer, feature, and plan, and pricing, meaning the provider rate and any discount. Together they turn a trace into a cost on a customer's account.

AI cost allocation vs AI cost attribution

AI cost attribution traces a direct cost to the request that caused it. A model call made for customer A is charged to customer A.

AI cost allocation splits a shared cost that no single request caused. Embeddings for a shared index, a vector database, and reserved GPU capacity all serve many customers at once, so you divide them by a rule, such as share of tokens.

Most teams need both. Attribution covers model and tool calls, allocation covers shared infrastructure, and the two add up to cost per customer. This guide covers each.

Why AI cost per customer is hard to measure

AI cost per customer is hard to measure because the provider bills you for usage, and your customers never appear on that bill. Everything that links a call to a customer has to come from your own system, and several common patterns break that link:

  • One API key shared across features. The provider sees one account, so its usage dashboard can't separate your support agent from your search feature.
  • Model routing. A router picks the model per request, so two identical requests can cost very different amounts.
  • Tools billed outside the model. Web search, code sandboxes, vector queries, and third-party APIs each send their own invoice, and none of them knows which customer the call served.
  • Sub-agents. When an orchestrator hands work to a sub-agent, the customer ID often doesn't travel with it, and that cost lands in a shared bucket.
  • Discounts applied after the fact. Cached tokens and batch jobs are billed at lower rates, so pricing every call at list rate overstates cost.
  • Silent retries. A failed step retries automatically. The provider bills every attempt, while your logs may count the work once.

Each of these is fixable, but only if you design for it before the data is gone. For the detailed version, including the five places attribution most often fails and a ten-field checklist for every usage record, read how to track LLM costs per customer.

What to tag: the attribution dimensions

Every model call and tool call needs a small set of fields attached at the moment it happens. These are the dimensions you will later group cost by, so anything you leave out now is a view you can't build later.

FieldWhy it mattersExample
Customer or tenant IDThe unit you bill and report margin oncus_8421
FeatureShows which part of the product drives spendsupport-reply
AgentSeparates cost when one product runs several agentstriage-agent
Agent run IDGroups every call in one run, including sub-agentsrun_7f3a91
Model and providerThe model actually used sets the rateopenai / gpt-5.4-mini
Input, output, and cached tokensEach is priced at a different rate12,400 in / 800 out / 9,000 cached
Tool callsBilled separately from tokensweb_search x 3
Retry flagCounts the cost of retries without counting the work twiceattempt=2
EnvironmentKeeps test and evaluation traffic out of customer costproduction

For the field names, use the OpenTelemetry GenAI semantic conventions instead of inventing your own. They define standard span attributes such as gen_ai.provider.name, gen_ai.request.model, gen_ai.response.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and gen_ai.usage.cache_read.input_tokens. Customer, feature, and plan IDs aren't part of the standard, so add them as your own attributes with a consistent prefix. The conventions are still marked as in development, so pin the version you build against.

Tags can be added in three places:

  • Application code. The developer sets the fields on each call. This gives full control, but every new call site is a chance to forget one.
  • An SDK wrapper. A thin layer around the provider client reads customer and feature from the request context and adds them to every call.
  • An AI gateway. A proxy between your services and the providers tags calls from request headers and records token counts as responses come back.

Wherever you add them, read customer and feature from the request context rather than hard-coding them, and flag any call that arrives without a customer ID.

3 ways to attribute AI cost

There are three ways to do AI cost attribution, and they differ in how much they cover and whether cost ever meets revenue. Most teams start with the first, move to the second as call volume grows, and need the third once they price on usage.

Method 1: Manual tagging in application code

Developers add customer, feature, and agent fields to each model call and write the token counts to a log or a table. A script then multiplies tokens by provider rates.

This gives you the most control, because you decide exactly what gets recorded. It also takes the most engineering effort, and tags drift over time. A new feature ships without its tag, someone renames a field, and the reports quietly lose accuracy.

Method 2: An SDK wrapper or AI gateway

A wrapper around the provider SDK, or a gateway that every request passes through, captures tokens and metadata on every call automatically. You set the customer ID once in the request context and the layer does the rest.

This needs far less code and covers model calls well. It often misses the rest: tools billed by other vendors, sub-agents that call providers directly, and shared infrastructure like a vector database. The output is cost, which still has to be joined to billing data before anyone can see margin.

Method 3: Billing-linked attribution

The provider cost of each call is recorded on the same usage signal you bill the customer for. When an agent run finishes, one record holds what the customer was charged and what the run cost you.

Because cost and revenue live on one record, margin per customer is available as soon as the run is billed, without a monthly export or join. This works best when usage-based billing and metering already sit in one system.

MethodSetup effortCoverageLinks to revenueBest for
Manual tagging in codeHigh, and ongoingWhatever developers remember to tagNoEarly products with a few call sites
SDK wrapper or AI gatewayMediumModel calls; often misses tools and shared costsNoTeams that need cost per customer fast
Billing-linked attributionMedium, onceEvery billed signal, including tools you meterYesCompanies that price on usage, credits, or outcomes

How to track LLM cost per customer, step by step

Tracking LLM cost per customer takes seven steps, from a single instrumentation point to an alert when a customer's margin slips.

Flow diagram of AI cost attribution: LLM and tool calls are tagged at one point with customer, feature, agent, run, and model; each call is priced at the rate in effect with discounts; calls roll up by run into cost per customer, including allocated shared costs; joined with revenue per customer, this gives margin per customer, per agent, and per model.
AI cost attribution flow · from LLM call to cost per customer and margin

Each call picks up its tags at one instrumentation point, gets priced at the rate that applied, and rolls up by run into cost per customer. Joined with revenue, that becomes margin.

  1. Route every model and tool call through one instrumentation point. Pick one place where calls are captured: a shared SDK wrapper or an AI gateway. A call that bypasses it is spend you can't attribute. To find stragglers, compare your call counts against each provider's usage dashboard every week until they match.
  2. Attach the attribution dimensions to each call. Add customer, feature, agent, run ID, model, and environment from the table above. Read them from the request context so a developer can't forget them, and flag any call that arrives without a customer ID instead of dropping it.
  3. Price each call at current provider rates, including discounts. Token prices differ by model and by token type. On most current OpenAI and Anthropic models, a cached input token costs about a tenth of a standard one, and both batch APIs take 50% off. Anthropic also charges extra to write to the cache. Keep a rate table with an effective date on each rate, so every call is priced at the rate in force when it ran.
  4. Roll calls up into the unit you bill on. Customers don't buy model calls. They buy a conversation, a completed run, or a resolved ticket. Sum every call that shares a run ID, so a support conversation that made six model calls and two tool calls shows as one cost against one billable unit.
  5. Reconcile against provider invoices every month. Add up your attributed cost per provider and compare it with the invoice. A gap of 2-3% is normal, caused by rounding, retries, and mid-month price changes. Anything larger usually means calls are bypassing your instrumentation point, so investigate it before you trust the per-customer numbers.
  6. Join cost to revenue per customer. Pull what each customer paid for the same period from your billing system and match it to their cost. This gives margin per customer. The join is easiest when cost and revenue already sit on the same record, which the margin section below covers.
  7. Set alerts for customers whose margin drops below target. Choose a target, such as 60%, and alert when any customer falls below it. Also alert when cost per run jumps by more than a set amount, because that is often the first sign of a model change or a prompt that grew.

LLM cost tracking for multi-model and multi-agent stacks

LLM cost tracking gets harder once you route between models and run agents that call other agents. Three rules keep it accurate.

Record the model actually used, not the one requested. A router or a fallback can send a request meant for a small model to a large one. Aliases also resolve to dated versions with their own prices. Price each call on the response model, which OpenTelemetry records as gen_ai.response.model, rather than on gen_ai.request.model.

Pass the parent run ID down to sub-agents. When an orchestrator starts a sub-agent, hand it the customer ID and the parent run ID. Every call the sub-agent makes then rolls up into the original run, instead of landing in an unassigned bucket.

Capture tool and API costs on the same run. Web search, code execution, browser sessions, and third-party data APIs are billed separately from tokens, often by a different vendor. Record the tool name, the quantity, and the unit price on the run that made the call, so a run's cost includes everything it used.

How to allocate shared AI costs

Some AI costs serve every customer at once, so no single request can carry them. The usual shared items are:

  • embeddings for a shared index or knowledge base
  • a vector database
  • reserved or committed GPU capacity
  • evaluation runs and model testing
  • background jobs such as re-indexing, summarization, and monitoring

These costs need an allocation rule. Three rules cover most cases.

RuleHow it worksProsCons
Proportional to tokensEach customer gets the share of shared cost that matches their share of total tokensTracks actual load closely; heavy users carry moreOvercharges customers with long prompts but little retrieval or storage
Proportional to requestsEach customer's share matches their share of requestsSimple to explain; easy to computeTreats a 200-token request and a 50,000-token run the same
Fixed per-customer shareEach customer, or each plan tier, carries a set amount per monthPredictable; good for costs that don't scale with useIgnores real usage, so outliers stay hidden

Pick one rule per cost type, write it down with finance, and apply it the same way every month. Evaluation runs might be split by tokens, while a fixed GPU reservation is split as a fixed share per plan. What matters is that the rule is agreed before you report margin, so a change in a customer's margin means their usage changed, not your method.

From cost per customer to margin per customer

Cost per customer is the sum of what you can trace and what you share:

Cost per customer = direct attributed cost + allocated shared cost

Margin per customer compares that cost with what the customer pays:

Margin per customer = revenue − cost per customer

Here are three customers for one month. Shared costs of $1,000 are allocated by share of tokens. The figures are illustrative.

CustomerRevenueAttributed costAllocated shared costCost per customerMargin
A$12,000$3,900$300$4,20065%
B$8,000$2,600$200$2,80065%
C$20,000$17,900$500$18,4008%

Customer C is the largest account on a revenue report and the weakest on this one. It runs long research tasks on an expensive model, so almost all of its $20,000 goes back out to the provider. Without cost per customer, C looks like your best account.

Where most attribution tools stop

Most attribution tools stop at cost. To see margin, someone exports cost per customer, exports revenue from billing, and joins the two in a spreadsheet. The join breaks in familiar ways: customer IDs don't match across systems, billing periods don't line up with usage periods, and the work happens weeks after the month closes.

Recording provider cost on the same signal you bill removes the join. Clocknext's margin control records what each usage signal cost at the provider next to what you charged for it, so margin per customer, per offering, and per invoice comes from one record. It also flags offerings priced below their cost to serve. Revenue insights puts that margin next to revenue for each customer.

Three decisions margin data enables

  • Reprice an offering whose cost has drifted above what the plan assumed.
  • Move a customer to a better-fit plan, for example from a flat fee to credits that charge more for runs on expensive models.
  • Set a discount floor for sales, so no deal is signed below your target margin.

LLM cost tracking tools: what to look for

LLM cost tracking tools fall into three categories. Each starts from a different team's problem, so the right choice depends on who needs the answer.

  • LLM observability tools, such as Langfuse, Helicone, and Traceloop, start from traces. They are built for engineers debugging prompts, latency, and token use, and most add cost per request on top.
  • FinOps platforms, such as Finout, CloudZero, and DoiT, start from cloud and vendor bills. They are built for finance teams allocating spend across the company, and AI is one more line they cover.
  • Billing platforms with cost tracking, such as Clocknext, Paid.ai, and Amberflo, start from the usage you bill. They record cost on billable usage, so margin sits next to revenue.

Many teams use more than one: observability for engineering, and a FinOps or billing platform for cost per customer. Whichever you evaluate, check it against this list.

CapabilityWhy it mattersQuestion to ask the vendor
Multi-provider coverageMost products use more than one model providerWhich providers and models do you price out of the box?
Tool and sub-agent cost captureTokens are only part of a run's costCan a tool call or a sub-agent roll up into the parent run?
Discount-aware pricingList rates overstate cost when caching and batch applyDo you price cached tokens and batch calls at their real rates?
Shared-cost allocationSome costs can't be traced to one requestCan I split a shared cost by tokens, requests, or a fixed share?
Link to revenue and marginCost alone doesn't tell you who is profitableDo you show margin per customer without an export?
AlertsMargin drift is easiest to fix earlyCan I alert on a customer's margin or cost per run?
ExportFinance will want the data in its own toolsCan I export attributed cost by customer, feature, and agent?

Best practices for AI cost attribution

These six practices keep AI cost attribution accurate as your product, models, and customer base change.

  1. Tag at the source. Attach customer, feature, and agent IDs when the call is made. Attribution rebuilt from provider invoices later is an estimate at best, because the invoice never knew who the call was for.
  2. Record the model actually used and the discount that applied. Price on the response model, and store whether tokens were cached or batched. Otherwise routing and discounts make your numbers wrong in both directions.
  3. Reconcile against provider invoices every month. Compare attributed cost with what you paid. Track the gap as its own number and investigate when it rises above 2-3%.
  4. Agree allocation rules with finance before you report margin. Decide how shared costs are split and write it down. A margin figure that changes because the method changed will not be trusted twice.
  5. Review margin per customer monthly, not quarterly. Costs drift every time a prompt, tool, or model changes. A monthly review catches drift while it is a few points, not a few quarters.
  6. Treat a model change as a pricing event. When you switch models or a provider changes its rates, check cost per run and margin for the affected customers within the week.

FAQ

What is AI cost attribution?

AI cost attribution is the practice of linking AI spend to the business activity that caused it. Every model call, tool call, and token is tagged with the customer, feature, agent, and model involved, then priced at the provider's rate. The result is a view of cost per customer, per feature, and per agent, instead of a single provider invoice. AI cost attribution matters because AI products pay for every request, so knowing which customers are expensive to serve is essential for pricing and margin.

How do you calculate LLM cost per customer?

To calculate LLM cost per customer, record the tokens and model used on every call and tag each call with the customer ID. Multiply tokens by the provider's rate for that model, including any cached-token or batch discounts, then add tool and API costs billed separately. Sum all calls for each customer over the period and add their share of allocated shared costs, such as embeddings or vector storage. Finally, reconcile the total against provider invoices so the per-customer figures add up to what you actually paid.

What is the difference between AI cost attribution and AI cost allocation?

AI cost attribution traces a direct cost to the request that caused it, so a specific model call is charged to a specific customer. AI cost allocation splits a shared cost that can't be traced to one request, such as a vector database, reserved GPU capacity, or background evaluation jobs, using a rule like share of tokens or share of requests. Most AI companies need both: attribution for model and tool calls, and allocation for shared infrastructure, combined into one cost-per-customer figure.

How do you attribute OpenAI and Anthropic costs to customers?

Provider invoices don't show which of your customers caused the spend, so attribution has to happen in your own system. Route every OpenAI and Anthropic call through one instrumentation point, such as an SDK wrapper or AI gateway, and attach the customer ID, feature, and agent to each request. Record the token counts each provider returns in its response and price them at current rates. Grouping those records by customer gives cost per customer across both providers, which you then reconcile against each monthly invoice.

What is cost to serve for an AI product?

Cost to serve is the total cost of delivering your AI product to a customer over a period. It includes model and token costs, tool and third-party API calls, and an allocated share of infrastructure such as embeddings, vector databases, GPUs, and monitoring. Subtracting cost to serve from the revenue you earn from that customer gives gross margin per customer. For AI products, cost to serve varies widely between customers on the same plan, which is why it needs to be tracked per customer.

Can you attribute AI costs retroactively?

Partly. If you kept raw request logs with token counts and some identifier, you can join them to customers later and rebuild cost per customer. If calls were made without customer or feature tags, you can only estimate using allocation rules, such as splitting spend by request volume, which hides the real outliers. The reliable approach is to tag every call at the source from now on and treat retroactive figures as estimates. Most teams start tagging first, then backfill only what their logs allow.

How does AI cost attribution affect pricing?

AI cost attribution shows what each customer, feature, or agent costs you to serve, which tells you whether your prices cover cost and leave the margin you need. With attributed cost, you can spot plans that lose money on heavy users, set credit rates that track real model cost, and know how much discount a deal can carry. It also shows when a model change has quietly raised cost, so you can reprice before margin erodes rather than finding out at the end of the quarter.

Start attributing AI cost to every customer

The method comes down to four moves. Tag every call at the source with customer, feature, and agent. Attribute direct cost at the rate that actually applied. Allocate shared cost by a rule you agreed with finance. Then join cost to revenue, so you see margin per customer instead of spend per provider.

The last step is where most setups stall, because cost and revenue live in different systems. Clocknext records provider cost on the same usage signal you bill, so margin per customer is there from the first invoice, with no export and no spreadsheet join. See it on your own usage data.

Book a demo · Start for free

Cost attribution, Provider cost, Margin

Manish Balaji

Manish Balaji

Head of Marketing at Clocknext

A fan of compelling stories, memorable product experiences, and Liverpool FC, not necessarily in that order.