重叠民意调查,没有任何事情被计算两次:Retailbox Automation 的 n8n 模板跟踪每个工作流程的 LLM 代币支出,逐个节点进行解释
给经营 n8n 客户流程的团队提供成本监控模板:定时读取执行记录、去重计算模型用量,按流程比较每日预算,再发 Slack 警报或暂停超额流程。
Reddit 原帖
在 Reddit 查看Overlapping polls, nothing counted twice: Retailbox Automation's n8n template that tracks LLM token spend per workflow, explained node by node
Not my template: it is Retailbox Automation's, published on n8n.io in October 2026. The video stops on each step: a Schedule Trigger fires every 15 minutes, and an Edit Fields node holds the settings: a price per 1M input and output tokens for each model, a daily budget ($5 by default), per-workflow budget overrides, and a pause switch that is off. An n8n node reads the last 100 executions of active workflows through the n8n API. A Code node walks each execution's run data, finds every chat model call, takes its token usage (or n8n's own estimate when the provider returned none), matches the model to the price list by its longest prefix, and outputs one row per call with a cost in USD.
Two Data Table nodes follow: the first keeps a call only if its callKey is not in the table yet, the second inserts the new rows. A third reads back every row finished since midnight. Another Code node sums the spend per workflow, compares it with the budget, and uses workflow static data so each workflow is flagged at most once a day. An If node follows the pause switch: true unpublishes the workflow through the n8n API, then both paths end on a Slack message with the workflow's name, today's spend, the budget and the number of calls.
What I like: the poll deliberately overlaps (the same 100 executions come back every 15 minutes), and the "row does not exist" check on a unique call key is what makes that safe. No cursor to store, nothing counted twice.

















