← Blog

AI agent cost tracking

How to track the cost of every AI agent step

July 17, 20268 min read

To track AI agent costs, attribute token spend to each step of each run instead of watching a single monthly provider bill. Capture the model, tokens, and price for every node, roll those up per run and per workflow, and set hard caps so a runaway agent can never turn into a surprise invoice.

Most teams start with the only number their provider hands them: one monthly total. It goes up, and nobody can say why. Which agent spent the money? Which run? Which step inside that run looped three times when it should have run once? A single lump sum answers none of those questions, and by the time the invoice arrives the run that caused it is long gone. Real AI agent cost tracking starts from the opposite end — the individual step — and rolls up.

Why a provider bill isn't enough

A provider bill is an aggregate. It tells you what you spent across every model call your account made in a billing period, with no notion of your agents, your runs, or the shape of your workflows. That's fine for accounts payable and useless for engineering. When spend jumps 40% in a week, the bill can't tell you whether one workflow got more traffic, one model got swapped for a pricier one, or one agent developed a habit of retrying a tool call in a tight loop.

The gap is granularity. The bill's unit is "the month;" the unit you actually operate on is the step. Between those two lives every question worth asking: cost per run, cost per workflow, cost per customer, cost of the one node that quietly doubled. You cannot recover that detail after the fact by staring at a total — it has to be recorded at the moment each step runs, or it is lost.

Cost per step, not per month

The fix is to move the unit of measurement from the billing period to the node. Every agent step — an LLM call, a tool invocation, a branch that itself calls a model — is a place where tokens get spent, so every step is a place where cost gets recorded. Tracking LLM cost per stepmeans each node carries its own price tag, and a run's total is the sum of the steps it actually executed, not an estimate.

This granularity is what makes cost debuggable. A run that cost more than its neighbors stops being a mystery: you open it, read down the steps, and see exactly which node was expensive and why — a larger model, a bigger context, or a step that ran more times than you expected. Cost per step turns a billing surprise into an ordinary code review.

The mental model: the monthly bill is a shadow of thousands of steps. If you record cost where it happens — at the node — the total explains itself.

Attributing tokens to nodes

AI agent cost attribution is the mechanism underneath cost per step. As each node runs, it records three things: the model it called, the tokens it consumed, and the pricefor that model. That triple is enough to compute the node's exact cost with no estimation — no dividing a monthly total by a guessed request count, no modelling averages.

Once every node carries its own cost, the rollups are just arithmetic. Sum the nodes in a run and you have the cost of that run — and remember a run is one execution of a workflow, so this is the true cost of doing the work once. Sum runs by workflow and you have the cost of that workflow over time. The same per-node records answer "what did this run cost" and "what does this agent cost us per day" without any separate accounting pipeline.

  • Per node: model, tokens, and price recorded the moment the step executes.
  • Per run: the sum of every node in one execution of the workflow.
  • Per workflow: runs rolled up over time, so you can see which agents are cheap and which are quietly expensive.

Unified cost across providers

Agents rarely stay on one provider. One node may want a frontier model from Anthropic for a hard reasoning step while another uses a cheaper OpenAI model for a quick classification. That's good engineering — but if each provider reports spend in its own dashboard, in its own format, your "total cost" becomes a spreadsheet you maintain by hand.

The answer is to put both providers behind one interface and track their cost in one place. Anthropic and OpenAI are supported behind a single interface with unified cost tracking, and each node picks its own model. Because the per-node record already captures model, tokens, and price, a run that mixes providers still produces one honest number — the interface normalizes the spend so cost per step is comparable no matter who served the tokens.

Hard caps and cap-and-notify

Attribution tells you what you spent; caps decide what you're allowed to spend. The whole point of tracking cost this closely is to be able to cap AI agent spend before a heavy day or a looping workflow turns into a bill nobody approved. An agent that retries forever, or fans out wider than intended, is a real failure mode — caps are what keep it from becoming an expensive one.

So caps are on by default. Every tier has hard caps with cap-and-notify as the default behavior: when a workspace approaches its limit you're notified, and the cap holds rather than silently letting spend run past it. If you'd rather keep running past the cap, auto-overage is opt-in per workspace — and the per-run pricing is shown to you before you enable it, so continuing is a decision you made on purpose, not a surprise you discover later.

The default is safe: a runaway agent hits a wall and pings you. Spending past the wall is something you turn on deliberately, with the price in front of you.

Pass-through vs markup, and bring-your-own-keys

Once cost is attributed per step, how it's billed should be just as transparent. There are two costs in play and they're kept separate. The platform fee meters runs — you pay for executions of your workflows. LLM token costs are a different line: on paid tiers they pass through at cost, itemized separately from the platform fee, so you can always see what went to tokens versus what went to the platform. No hidden markup buried inside a single blended number.

If you'd rather the platform never touch your token billing at all, bring your own keys. On Pro and Enterprise you can supply your own provider keys, and with bring-your-own-keys nothing is billed for tokens — they land on your own Anthropic and OpenAI accounts directly. Cost tracking still works exactly the same: every node still records model, tokens, and price, so you keep full per-step attribution while the actual charges go straight to your provider.

How Ballast tracks cost

Ballast is built so that cost is a first-class property of every run, not an afterthought reconstructed from a bill. 100% of steps are cost-attributed— every node records its model, tokens, and price, and those roll up per run and per workflow automatically. A costs console puts those rollups in front of you, so "which run was expensive and why" is a question you answer by looking, not by guessing.

Because Anthropic and OpenAI sit behind one interface with unified cost tracking, a workflow that mixes providers still produces one number you can trust. Hard caps with cap-and-notify are on by default on every tier, auto-overage is opt-in with per-run pricing shown first, and token costs pass through at cost on paid tiers — or vanish from your bill entirely if you bring your own keys. See the full model on the cost tracking page and the tier details on pricing.

Where to go next

  • See how per-step attribution and the costs console work on the cost tracking page.
  • Compare caps, pass-through token pricing, and bring-your-own-keys across tiers on pricing.
  • See where cost tracking fits alongside the rest of the runtime on the product page.

Frequently asked questions

How do you track the cost of an AI agent?
Attribute token spend to each step of each run rather than reading a single monthly provider bill. Record the model, tokens, and price for every node, then roll those up per run and per workflow so you can see exactly which agent and which step spent the money.
How much does it cost to run an AI agent?
It depends on the models and token volume each step uses. The only way to know for your workload is per-step cost attribution: capture the cost of every node so you can see the real cost of a run and a workflow instead of guessing from a lump-sum bill.
Can you cap how much an AI agent spends?
Yes. Hard caps by default stop runs beyond your limit until you raise the cap, so a looping or runaway agent can't produce a surprise invoice. Any auto-overage is opt-in, with per-run pricing shown before you enable it.

Run agents that survive crashes.

Ballast is the durable runtime for production AI agents. Checkpointed execution, human approval, and a cost on every step.