{"post":{"slug":"agent-cost-attribution-2026","title":"Agent Cost Attribution: Finding Where the Tokens Went","excerpt":"A single monthly API bill tells you that agents are expensive. It does not tell you which feature, which customer, or which retry loop is responsible. That gap is fixable.","category":"ai","date":"August 19, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">T</span>he bill arrives and it is larger than last month. Somebody asks why. The honest answer, in most organisations running agents, is that nobody knows — there is a total, there is maybe a per-model breakdown, and beyond that the spend is an undifferentiated mass. Which feature drove it? Which customers? Was it more usage or more expensive usage? The data to answer that was available at request time and nobody captured it.\n\nAttribution is the unglamorous discipline of tagging spend as it happens so that these questions have answers. It is not hard. It is just easy to postpone until the month you urgently need it, at which point the history you want does not exist.\n\n## What changed in 2026\n\n- **Agent workloads made per-request accounting insufficient.** One user action now fans out into many model calls across subagents, retries, and tool loops. Attribution had to move from \"cost per API call\" to \"cost per unit of work someone asked for\".\n- **Unit economics became a product question.** Teams shipping AI features started needing gross margin per feature, which is a different artefact from a cloud bill and cannot be derived from one.\n- **Caching complicated the arithmetic.** Cached input costs a fraction of fresh input, so two features with identical token counts can differ substantially in real cost. Attribution that does not split the two misranks them.\n- **Multi-tenant cost allocation stopped being optional.** Once one customer can trigger materially more spend than another on the same plan, per-tenant visibility becomes a pricing input rather than a nice-to-have.\n\n## What to tag, and where\n\nThe core practice is small: attach identifiers to every model call at the moment you make it, and carry them through nested calls.\n\n| Tag | Answers | Notes |\n| --- | --- | --- |\n| Feature / surface | Which product area costs what | The single most useful tag |\n| Task type | Which kinds of work are expensive | Enables routing decisions |\n| Tenant / customer | Who drives spend | Needed for pricing and abuse detection |\n| Trace ID | What one user action really cost | Ties fan-out back to a single request |\n| Model and effort | Whether config changes moved the needle | Makes tuning measurable |\n| Outcome | Cost of success vs cost of failure | Usually the biggest surprise |\n\nThe trace ID is the one people skip and later wish they had. Without it you can see that a hundred calls happened; you cannot see that eight of them were one user pressing one button. In a fan-out architecture that distinction is the whole picture — [subagent architecture](/blog/subagent-architecture-explained-2026) makes the aggregate look alarming until you learn how many calls constitute one task.\n\n## The line items people miss\n\n**Retries.** A call that failed and was retried cost money twice and produced value once. Most reporting counts it as ordinary usage. If your retry rate moves, your cost per successful task moves with it, and nothing in a token-total dashboard will show that.\n\n**Abandoned work.** An agent that ran for forty steps before the user navigated away consumed real budget. Whether you count that as feature cost or waste is a decision worth making deliberately, because leaving it uncounted flatters your unit economics.\n\n**Input you did not write.** Agents that read files, fetch pages, or receive large tool results pay for those tokens. Teams modelling cost purely on generated output routinely under-forecast by a wide margin, particularly on research-style workloads.\n\n**Cache reads versus cache writes.** Writing to cache costs more than ordinary input; reading from it costs much less. A feature with a stable prompt prefix and high traffic can be dramatically cheaper per call than its raw token count implies. [Prompt caching](/blog/prompt-caching-explained-2026) explains the mechanism; the point for attribution is that you must record the split, not just the total.\n\n**Evaluation traffic.** Judge models scoring production samples are real spend, and they scale with the traffic they measure. Tag them separately or they will quietly inflate whichever feature they happen to be evaluating.\n\n## Turning numbers into decisions\n\nAttribution that does not change a decision is telemetry theatre. Three questions justify the effort.\n\n**Which feature is worth its cost?** Cost per task next to the value of that task is the only comparison that matters. A feature costing more per use than it returns is a product decision, and it stays invisible under an aggregate bill.\n\n**Where would routing help?** If one task type dominates spend and is not the hardest work you do, it is a candidate for a cheaper model or a lower effort setting. Attribution is what identifies the candidate; [reasoning effort controls](/blog/reasoning-effort-controls-2026) is what you do about it.\n\n**Is anyone unprofitable?** In per-seat pricing, per-tenant attribution reveals the distribution behind the average. There is usually a tail, and finding it before it grows is considerably easier than after.\n\n## Common mistakes\n\n- **Reconstructing attribution from logs after the fact.** Always incomplete, always disputed, always more work than tagging would have been.\n- **Tagging only the top-level call.** Nested subagent calls inherit nothing and become an unattributed remainder that grows over time.\n- **Reporting tokens instead of money.** Token counts are not comparable across models. Convert to cost at ingest.\n- **Ignoring the cache split.** Two identical token counts can differ several-fold in real cost.\n- **Too much granularity.** Per-request dashboards are impressive and unused. Attribute at the level you would act on.\n- **No baseline before an optimisation.** Without a before, the after is a number with no meaning.\n\n## FAQ\n\n**Is this not just what my provider's dashboard shows?**\nProvider dashboards report by API key, model, and time. They do not know what a feature is, which customer triggered a call, or that six calls were one task. Those are application-level facts only your code can supply.\n\n**How much overhead does tagging add?**\nEffectively none at request time — it is metadata on a call you are already making. The real cost is the discipline of threading identifiers through nested calls, which is a small amount of plumbing that gets much harder to retrofit later.\n\n**What granularity should I start with?**\nFeature and trace ID. Those two answer most questions and are the hardest to add retroactively. Tenant next if you are multi-tenant. Everything else can wait.\n\n**How does this relate to observability?**\nIt is the same instrumentation viewed through a different lens — the traces from [AI agent observability](/blog/ai-agent-observability-2026) already carry most of the structure. Attribution is largely a matter of attaching cost to spans you are probably already emitting.\n\n## Where to go next\n\nFor bounding spend once you can see it, read [agent token budgets](/blog/agent-token-budgets-2026). For benchmarking your figures against typical workloads, [AI agent cost per task](/blog/ai-agent-cost-per-task-2026), and for the broader set of levers, [AI inference cost optimization](/blog/ai-inference-cost-optimization-2026).","hue":220,"metaTitle":"Agent Cost Attribution: Find Where Tokens Went","metaDescription":"How to attribute AI agent spend to features, customers, and task types — what to tag at request time, and why retries and cache hits change the picture.","keywords":["agent cost attribution","llm cost tracking","ai spend per feature","token cost accounting","ai unit economics","llm cost per customer","agent billing visibility","ai cost observability 2026"],"tldr":["**Tag at the request, not in a spreadsheet later** — attribution you reconstruct after the fact is always incomplete and always contested.","**Cost per task beats cost per token** — a token price says nothing useful until you know how many calls one user action actually triggers.","**Retries and failures are a real line item** — work that produced no value still burned budget, and it is usually invisible in aggregate reporting.","**Cached reads cost a fraction of fresh input** — attribution that ignores the cache split will misjudge which feature is actually expensive.","**Skip:** per-request dashboards nobody opens. Attribute at the granularity you would act on — feature, customer tier, task type — and stop there."],"readTime":"5 min read","wordCount":1151},"related":[{"slug":"ai-cost-monitoring-tools-2026","title":"AI Cost Monitoring Tools in 2026: Keeping LLM Spend in Check","excerpt":"How teams track and control LLM spend in 2026 — token-level attribution, budget alerts, and the cost monitoring tools that catch runaway usage early.","category":"ai","date":"July 4, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":280},{"slug":"ai-agent-cost-per-task-2026","title":"AI Agent Cost Per Task: The Number That Actually Matters","excerpt":"Cost per token tells you nothing about whether an agent is economical. Here is how to compute cost per successful task and what usually dominates the total.","category":"ai","date":"August 17, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":204},{"slug":"agent-token-budgets-2026","title":"Agent Token Budgets: Capping Spend Without Cutting Off","excerpt":"A max_tokens ceiling stops an agent mid-sentence. A task budget tells it how much it has so it paces itself and lands the plane. The difference matters more than it sounds.","category":"ai","date":"August 13, 2026","author":"ByteLedger Team","readTime":"6 min read","hue":212}],"sameCategory":[{"slug":"human-in-the-loop-agents-2026","title":"Human-in-the-Loop Agents: Where to Put the Approval Gate","excerpt":"Approve everything and the agent is a slow autocomplete. Approve nothing and you have handed irreversible actions to a system that can be talked into things.","category":"ai","date":"August 19, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":197},{"slug":"reasoning-effort-controls-2026","title":"Reasoning Effort Controls: Tuning How Hard a Model Thinks","excerpt":"Fixed thinking budgets gave way to effort levels, and the default is rarely the right setting. Here is how the dial behaves and where each level actually belongs.","category":"ai","date":"August 19, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":210},{"slug":"retrieval-metrics-explained-2026","title":"Retrieval Metrics: Measuring the Half of RAG That Fails","excerpt":"When a RAG system answers badly, the retrieval usually failed before the model ever spoke. Measuring generation quality alone hides that entirely.","category":"ai","date":"August 19, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":215},{"slug":"reward-hacking-explained-2026","title":"Reward Hacking: When Models Optimize the Wrong Thing","excerpt":"A system trained on a proxy will exploit the gap between the proxy and what you meant. Here is how reward hacking shows up in practice and how to catch it.","category":"ai","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":196}],"newer":{"slug":"83b-election-explained-2026","title":"The 83(b) Election: A Form With a Hard Deadline","excerpt":"Filing an 83(b) election taxes restricted stock at grant instead of at vesting, which for early-stage equity is usually a large win. The deadline is unforgiving.","category":"finance","date":"August 19, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":284},"older":{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145}}