How to measure AI agent cost per customer in a SaaS product
To measure what your AI agents cost per customer, tag every LLM call with the customer (tenant) it served and the feature or agent that made it, record the provider's usage fields including cached tokens, price each call at what it actually cost (cache writes, cache reads, fresh input and output priced separately), and roll the result up by customer and feature next to what each customer pays you. The hard parts are the calls that lose their tag (background jobs, retries, sub-agents), cached tokens that several customers share, and GPU cost when you host your own models. Once you can see cost per customer, the biggest lever is usually not the heaviest customer but the waste every customer's runs share, because in a product that waste is multiplied by your whole customer base.
Why per-customer cost matters for agents
In a SaaS product, agents run for every customer and the company pays for every token, so inference is cost of goods: it grows with usage and lands on gross margin. Agents make it bigger than chat features do: Anthropic reported that in its data, agents use about 4x the tokens of chat interactions, and multi-agent systems about 15x (Anthropic, Jun 2025). Averages hide the problem. Customers use agent features very differently, and a flat-priced plan can be profitable for most accounts and loss-making for the few that use the agent heavily. You can't price, limit or fix that without seeing cost per customer.
Step 1: tag every call
Every LLM call needs, at minimum:
- customer or tenant ID: the account the work was done for
- feature or agent name: which product surface made the call
- run or session ID: to group calls into one task
- model and provider, and the usage fields, including cache reads and writes
Where to put the tags depends on your stack. Langfuse traces carry a user ID, session ID, tags and metadata. LangSmith runs carry metadata and tags. With OpenTelemetry, the GenAI semantic conventions cover model and usage (gen_ai.usage.*), but there is no standard tenant attribute, so add your own span attribute (for example tenant.id) consistently. A gateway in front of all LLM traffic can enforce the tag on every request.
The calls that lose their tag are predictable: scheduled and background jobs, retries, sub-agents spawned by a parent agent, and calls made from shared libraries. Pass the tenant through the context explicitly and check the share of untagged spend every week. If it grows, attribution is drifting.
Step 2: price each call as it was billed
Multiplying total tokens by a list price gets per-customer cost wrong, sometimes badly:
- Cache reads, cache writes and fresh input have different prices. A customer whose runs mostly hit the cache costs much less per token than one whose runs keep writing it.
- Output tokens cost more than input tokens. Agents that write long answers or long tool arguments cost more per call.
- Batch and flex pricing, and discounts, apply per request. Price the request at the rate it actually got.
Use the usage fields on each response (on Anthropic, cache_creation_input_tokens and cache_read_input_tokens; on OpenAI, usage.prompt_tokens_details.cached_tokens) and the price table for that model on that date. Then reconcile the sum against the provider invoice. If the two don't match, find the gap before trusting any per-customer number.
Step 3: decide how to split shared cost
Some cost isn't caused by any one customer:
- Shared cached prefixes. If many tenants share a system prompt and tool block, the first call writes the cache and later calls read it. Charging the write to whichever customer happened to be first is noise. Spreading it across the customers who read it is fairer.
- Platform overhead. Evals, monitoring agents and internal tooling are product cost but not any customer's cost. Report them separately.
- Self-hosted models. With your own GPUs there is no per-token invoice. Allocate GPU hours by the work each customer's requests caused, roughly by tokens processed, and remember that prefix-cache hits skip most of the input processing for the shared part of the prompt.
Write the rules down and keep them stable, so a change in a customer's cost reflects a change in usage, not in accounting.
Step 4: compare cost to revenue
Put agent cost per customer next to what each customer pays, by plan. Useful views: cost per customer per month, cost per task by feature, and the share of customers on each plan whose agent cost exceeds what the plan can carry. This is the input to pricing decisions (usage limits, metered features, plan design), and to deciding which features are worth optimizing first.
Step 5: bring the cost down for every customer
Per-customer views tend to point at the heaviest accounts. The bigger lever is usually the waste every account's runs share: tool definitions sent on every call, a tenant field near the top of the prompt that gives every customer their own cache prefix, the same failing tool call in every account, lookups repeated in every run. Fixing one of those lowers cost for every customer at once. Where agents waste tokens covers how to find them.
A tenant-specific prompt is often unavoidable. Put the shared part of the prompt first and the tenant-specific part after it, so all customers share one cached prefix and only the tail differs. Before changing customer-facing agents, test the change on your recorded traffic so you know it saves money and doesn't change behavior: proving LLM savings before you ship.
Tools that help
- Observability (LangSmith, Langfuse, OpenTelemetry-based tracing) holds the tags and the usage fields.
- FinOps and attribution tools (Vantage, CloudZero, Finout) roll AI spend up by team, product and customer next to the rest of your cloud cost.
- Gateways can enforce tagging and per-customer budgets on every request.
A wider map of what each category does is in AI agent cost tools, mapped by category.
How Setta helps
Setta works from the same traces. It finds the waste that repeats across your customers' runs, proves each fix by replaying your real traffic in a cache-aware simulator checked against your bill, and keeps your agents current as models and prices change, so you can lower cost per customer without changing what your agents do for them. You send a trace export; there is nothing to install. Start with the free audit.