Cost per Useful Iteration (CIU) — measure the real cost of running AI agents in production. Companion code for the book Código Sintético / Synthetic Code (Chapter 11).
When a team runs AI agents without governance, Token-Burn appears: token spend that buys no value because
no system aggregates it. ciu-tracker makes it visible with one metric:
CIU = total token cost / features validated in production
The denominator is the key word: validated. Iterations that never reach production are not productivity — they are cost.
git clone https://github.com/sergioide007/ciu-tracker
cd ciu-tracker
python ciu_tracker.py # built-in smoke demo
python examples/demo.py # fuller two-feature walkthrough
python examples/gateway_integration.py # wire it into an AI Gateway (Ch. 3 + 11)
python -m unittest discover -s tests # run the test suiteNo dependencies beyond the Python standard library (3.10+).
ciu_tracker.py the metric, the ledger, the alert (≈ 60 lines of logic)
examples/demo.py two features, one number that tells them apart
examples/gateway_integration.py the one-line seam between transport and governance
tests/test_ciu_tracker.py unittest suite — also the executable spec of the rules
The tracker measures; it does not decide where an alarm goes. The alert sink is a
parameter (CIUTracker(alert_sink=...)), so adding Slack or PagerDuty never edits
the metric, and tests assert on alerts by injecting a list. That is the Dependency
Inversion principle doing real work — the same "SOLID como interrogatorio" the book
applies in Chapter 4 (Martin, 2017).
from ciu_tracker import CIUTracker
tracker = CIUTracker(alert_ciu_usd=5.0)
tracker.record("checkout-refactor", tokens=18_000, cost_usd=0.70, validated=False)
tracker.record("checkout-refactor", tokens=9_000, cost_usd=0.35, validated=True)
print(tracker.feature_ciu("checkout-refactor")) # cost per validated feature
print(tracker.monthly_report()) # team-level rollup + alert flagPlug record(...) into your AI Gateway so every call is covered automatically. The tracker alerts when a
feature's CIU crosses the threshold.
- Inflated context · 2. The wrong model · 3. Loops without stopping criteria · 4. No prompt caching ·
- Ungoverned verbosity. Plus one lever: batch whatever is not urgent (~50% cheaper).
Cuando un equipo opera agentes de IA sin gobernanza aparece el Token-Burn: gasto en tokens que no compra
valor porque ningún sistema lo agrega. ciu-tracker lo hace visible con una métrica:
CIU = costo total de tokens / funcionalidades validadas en producción
El denominador es la palabra clave: validadas. Las iteraciones que no llegan a producción no son productividad; son costo.
git clone https://github.com/sergioide007/ciu-tracker
cd ciu-tracker
python ciu_tracker.py # ejecuta la demo de humo incluidaSin dependencias más allá de la librería estándar de Python (3.10+).
from ciu_tracker import CIUTracker
tracker = CIUTracker(alert_ciu_usd=5.0)
tracker.record("checkout-refactor", tokens=18_000, cost_usd=0.70, validated=False)
tracker.record("checkout-refactor", tokens=9_000, cost_usd=0.35, validated=True)
print(tracker.feature_ciu("checkout-refactor")) # costo por feature validada
print(tracker.monthly_report()) # consolidado del equipo + alertaIntegra record(...) en tu AI Gateway para cobertura automática. El tracker alerta cuando el CIU de una
funcionalidad supera el umbral.
- 🇬🇧 The Silent Token-Burn and the CIU Metric — Medium
- 🇪🇸 El Token-Burn silencioso y la métrica CIU — LinkedIn
MIT © Sergio Perez Ruiz. See LICENSE.