ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-06-17Advanced

Accounting for Which Agent Spent What: A Cost Attribution Design by Task

Your month-end bill is one number, but running multiple agents on Gemini 3.5 Flash hides which task ate the cost. Separate from a budget guard, I share a cost-attribution accounting design that maps usage to per-task and per-site cost, with a solo-operator implementation and numbers.

antigravity365multi-agent44cost2finopsunit-costoperations14gemini15

Premium Article

The bill that arrived each month was always one total. Gemini 3.5 Flash is fast and cheap, and even running agents in parallel the per-call cost is small — or so I assumed. But running tasks across six sites together, I had no idea which site's which task ate how much of that total. A cheap operation can quietly dominate the bill through sheer volume, and you'd never notice.

Before lowering cost, I needed to make where it goes visible. This is a third kind of work, distinct from token-saving optimization and from a budget guard that cuts off spend. In accounting terms it is cost attribution: assigning incurred cost correctly to the unit that produced it. As an indie developer who watches the books alone, I can't make investment decisions while the unit cost stays invisible.

A budget guard and cost attribution are different jobs

They're easy to conflate, so let me separate them first. A budget guard "stops when a cap is exceeded" — it prevents runaway spend. Cost attribution "assigns spent cost to the task and site that produced it" — it produces material for decisions.

With a guard but no attribution, you can't see the state where "the total is within budget, but cost skews toward inefficient tasks." I myself ran with only a guard for a long time and felt safe. It didn't break the bank, but whether the allocation was optimal stayed unknown.

Attribution starts by tagging every model call with "who is this call for."

Tag every call with a cost tag

Attach three tags to each call — site, agent, and task type — so you can later slice cost along these axes.

interface CostTag {
  site: string;       // "antigravitylab"
  agent: string;      // "writer-1"
  taskType: string;   // "premium-article" | "link-audit", etc.
}
 
interface Usage {
  inputTokens: number;
  outputTokens: number;
  model: string;      // "gemini-3.5-flash", etc.
}
 
interface CostEntry extends CostTag {
  ts: string;
  model: string;
  inputTokens: number;
  outputTokens: number;
  costJpy: number;
}

Fill the tags automatically from the call-site context. Tag by hand and you will forget, so generate the CostTag where the agent is launched and pass it into the call wrapper.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Get the full TypeScript implementation of a cost ledger that tags every call and converts usage to currency
Learn the aggregation logic that rolls up cost by task and by site and exposes cost per published article
See the decision criteria and rules that cut monthly spend about 28% once unit cost became visible
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-06-17
Tracing Parallel Agents After the Fact: Observability with Structured Logs and Spans
Running multiple agents in parallel on the Antigravity 2.0 desktop makes it impossible to tell which one is doing what. I share an observability design that drops tangled print debugging for run_ids and spans you can trace afterward, with a solo-operator implementation and numbers.
Agents & Manager2026-06-17
Making Managed Agent Batches Safe to Re-run: Idempotency and Checkpoints
Running overnight batches on the Antigravity 2.0 Managed Agents API makes recovery from partial failure unavoidable. Starting from a duplicate-post incident, I share the implementation of idempotency keys, a checkpoint store, and resume logic, with real numbers from solo operations.
Agents & Manager2026-06-01
Capping Parallel Agents With a Token Budget — Designing a Guard That Stops Runaway Cost
Running many agents in parallel quietly inflates your token bill. This is not about shrinking prompts — it is about a governance layer that meters spend in real time and cuts it off at a budget. Full design and TypeScript implementation, drawn from running six sites autonomously.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →