Templates / Track AI agent token costs and store receipts with the n8n API and Data Tables

Track AI agent token costs and store receipts with the n8n API and Data Tables

Ready for 3.0

by Ben van Steenbergen · 221 views · created 2026-04-20 · Engineering, AI Summarization

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

What this workflow does

This workflow has 8 nodes and runs on a schedule (every day). It uses only n8n's built-in nodes.

How it runs

Trigger: On a schedule (every day).

  1. 1.1 Get AI Agent Workflows (n8n): uses n8n
  2. Loop Workflows (Loop Over Items (Split in Batches)): loops over the items in batches
  3. Loop Receipts (Loop Over Items (Split in Batches)): loops over the items in batches
  4. 1.2 Get Workflow Executions (n8n): work with execution
  5. Has Usage Data? (If): checks a condition and branches into true / false
  6. Extract Token Usage & Cost (Code): runs custom JavaScript code
  7. 1.3 Save Receipt to Data Table (Data table): uses Data table

Before you upgrade to n8n 3.0

Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.

Nodes used (6)

From the author

Ever wondered how much your AI Agent is costing you per run? I had no idea. You build an agent, it works great, but behind the scenes tokens are burning. And you just see the API-key cost as an aggregated value on Stripe, right? One workflow costs you $0.002.…

Excerpt from Ben van Steenbergen's description on n8n.io.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.