Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Cost Ledger: How I Gave Every n8n Workflow Run a Price Tag

Description and use

Implemented a cost ledger in n8n that logs each LLM call, aggregates daily spend per workflow, and alerts on spikes, enabling rapid cost control.

Problem

n8n executions log token usage per run but lack aggregation, making it hard to see which workflow drives cost spikes.

Outcome

The ledger enabled real‑time cost attribution per workflow, allowing rapid detection of cost spikes and preventing unnoticed budget overruns.

Workflow

  • Insert a Code node after every AI node to log call details
  • Store run_id, event_id, workflow, node, model, in_tokens, out_tokens, usd, timestamp in cost_log table
  • Schedule a daily workflow to query cost_log, compute daily spend per workflow, compare to 7‑day median, and calculate spike_ratio
  • Trigger Slack alert when spike_ratio >= 2.0

Evidence

n8n executions log token usage for some AI nodes, buried in execution data you have to open one run at a time. There's no aggregation: no "workflow X spent $Y this week," no per-node attribution, no trend.

Source

The design is boring on purpose. Right after every node that calls a model – OpenAI node, Anthropic node, an HTTP call to an inference endpoint – sits a Cost node.

Source

The alert rule is one line: spike_ratio >= 2.0 fires a Slack alert with the workflow name and yesterday's spend.

Source

  • Record date: 2026-10-14T22:56:00.396Z