---
title: How do you attribute LLM costs to individual AI agents?
url: https://opencontroller.lyzr.com/blog/how-to-attribute-llm-costs-to-ai-agents
published: 2026-11-11
updated: 2026-11-11
author: Lyzr
---

# How do you attribute LLM costs to individual AI agents?

**Attribute LLM costs to agents by tagging every model call with the agent's identity and version at the point where the call leaves your network, usually an LLM gateway. Record the model and the input, cached and output tokens for each call, multiply by the price of that model, and roll the results up by agent, version, owner and team.** Invoice-level cost data from model providers cannot do this on its own, because a single API key is often shared by many agents.

## Why can't you get per-agent cost from the provider invoice?

Provider billing is organised around accounts, projects and API keys. Agents are not. In most enterprises:

- several agents share one API key or one cloud project,
- one agent calls several models from different providers,
- the same agent runs in more than one version at once (for example during a canary release),
- agents built on SaaS platforms consume credits that are billed to the platform, not to a model provider.

So the invoice tells you *how much* you spent with each provider. It cannot tell you *which agent* spent it, or whether version 2 of an agent costs more than version 1. That attribution has to be captured per request.

## What fields do you need on every model call?

Capture these fields once per call. They are enough to calculate cost and to explain it later.

| Field | Why it matters |
| --- | --- |
| Agent ID | The unit you want to charge back |
| Agent version | Shows whether a release changed cost |
| Owner and team | Who pays and who answers questions |
| Environment | Separates production from test spend |
| Provider and model | Prices differ by model, often by 10x or more |
| Input tokens | Billed at the input rate |
| Cached input tokens | Many providers bill these at a discounted rate |
| Output tokens | Usually the most expensive tokens |
| Request outcome | Retries and failures still cost money |
| Cache hit at the gateway | A gateway cache hit avoids the model call entirely |

Token counts come back in the provider's response (the `usage` object in OpenAI-compatible APIs). The agent ID and version should come from the agent's own identity, not from a free-text header that a developer can forget or fake.

## How do you calculate cost per agent?

Use a simple formula per call, then aggregate:

1. **Price each call.** Cost = (input tokens − cached tokens) × input price + cached tokens × cached price + output tokens × output price.
2. **Add non-token charges.** Some calls also incur tool, search or image charges. Add them to the same record.
3. **Allocate shared overhead.** Gateway infrastructure, vector databases and evaluation runs are shared. Allocate them by share of calls or tokens, and label them as allocated, not measured.
4. **Roll up.** Sum by agent, then by version, owner, team and environment.
5. **Reconcile.** Compare the monthly total with provider invoices. A gap above a few percent usually means some traffic is bypassing the gateway.

A worked example with illustrative prices: an agent makes 1,000 calls a day, each with 4,000 input tokens (1,000 of them cached) and 500 output tokens. At $3 per million input tokens, $0.30 per million cached tokens and $15 per million output tokens, one call costs about $0.0090 + $0.0003 + $0.0075 = $0.0168. That is about $16.80 a day for the agent, before allocated overhead. If version 2 doubles the output length, its cost rises by about 45% even though nothing else changed.

## Where should attribution happen: in the agent or in the gateway?

You can instrument each agent to report its own usage. In practice this breaks down because coverage depends on every team doing it correctly. A gateway in the call path sees every request in the same format, so attribution is consistent. The trade-off is that only traffic routed through the gateway is measured. Read our [comparison of LLM gateways, agent gateways and control planes](/blog/llm-gateway-vs-agent-gateway-vs-control-plane) for where each layer sits.

For spend that never touches your gateway, such as credits consumed inside a SaaS agent platform, pull usage from the platform's own reporting and map it to agents in your registry. Discovery matters here: you cannot attribute cost to an agent you do not know exists. See [how to find every AI agent in your enterprise](/blog/how-to-find-shadow-ai-agents).

## How should you report agent costs?

Use a consistent schema so finance can join AI costs with the rest of cloud spend. The FinOps Foundation's FOCUS specification defines common columns for billing data and is a good target format for exports. Useful views:

- **Cost per agent per day**, with a trend line and the top 10 agents by spend.
- **Cost per version**, to catch regressions after a release.
- **Cost per successful task**, where the agent reports task outcomes. This is the number business owners care about.
- **Unattributed spend**, as its own line. If it grows, find out why.

## Checklist for per-agent cost attribution

- [ ] Every agent has a registered ID, version and owner
- [ ] Model traffic is routed through a gateway that reads the agent identity
- [ ] Input, cached and output tokens are recorded per call
- [ ] A price table per model and provider is maintained and versioned
- [ ] Retries, fallbacks and gateway cache hits are recorded
- [ ] Monthly reconciliation against provider invoices
- [ ] Unattributed spend is reported, not hidden

## How Opencontroller does this

Opencontroller's LLM Gateway (Lyzr Gateway) handles routing, fallback and retry, and caching, and attributes cost per agent and per version. Agents come from Opencontroller's governed registry, which is populated by auto-discovery of agents, models and API keys across AWS, Azure and Google Cloud. In an October 2026 benchmark on mixed synthetic traffic, caching lowered model cost by 23.5%, within the stated test conditions. See the [LLM gateway benchmark](/llm-gateway-benchmark) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Can I attribute cost per agent without a gateway?**
Yes, if every agent reports its own token usage with its ID. Coverage is usually incomplete, so most teams use a gateway for consistency and agent self-reporting as a fallback.

**Should cached tokens be charged back at full price?**
No. Charge what you actually pay. Showing the saving per agent encourages teams to design prompts that cache well.

**How do I handle an agent that calls other agents?**
Record the calling chain. Charge each agent for its own model calls, and report the full chain cost on the top-level agent as a separate view.

## Key facts

Per-agent LLM cost attribution requires per-call capture of agent ID, version, model and token counts. Opencontroller's LLM Gateway attributes cost per agent and per version. Oct 2026 benchmark: caching lowered model cost by 23.5% on mixed synthetic traffic (scoped to stated test conditions). Opencontroller pricing starts from $250K per deployment per year (annual licence, not per seat, not usage-based).

## Related

- [LLM gateway vs agent gateway vs AI control plane: what's the difference?](https://opencontroller.lyzr.com/blog/llm-gateway-vs-agent-gateway-vs-control-plane.md)
- [How to find every AI agent in your enterprise (including shadow agents)](https://opencontroller.lyzr.com/blog/how-to-find-shadow-ai-agents.md)
- [What is an AI agent control plane?](https://opencontroller.lyzr.com/blog/what-is-an-ai-agent-control-plane.md)
- [More on Gateways and cost](https://opencontroller.lyzr.com/blog/cluster/gateways-and-cost)
