Track AI Agent Costs with n8n Workflow Automation
Track AI Agent Costs with n8n Workflow Automation
Couldn't load pickup availability
Track AI Agent Costs with n8n Workflow Automation
Stop burning money on AI agent costs you can't see. This n8n workflow automatically tracks token usage and calculates exact costs for every AI agent execution, so you know which workflows are quietly draining your budget before your Stripe bill arrives.
What this workflow does
Every hour, this automation scans all your tagged AI agent workflows and provides complete cost visibility:
- Fetches all workflows tagged with "agent" via the n8n API
- Pulls execution data for each AI agent workflow
- Extracts exact token usage per model from each run
- Calculates estimated costs in USD for every execution
- Stores detailed receipts in a DataTable with workflow ID, execution ID, and cost breakdown
- Tracks usage units and timestamps for historical analysis
Use cases
Perfect for n8n users running multiple AI agents who need cost control and budget planning. Identify which workflows cost $0.002 per run versus those quietly racking up $2.00 each execution. Monitor token consumption patterns across different AI models, set up cost alerts when agents exceed budgets, and optimize expensive workflows before they impact your bottom line. Essential for agencies managing client AI automation costs or SaaS operators scaling AI-powered features.
Technical details
Built with core n8n nodes including IF conditions, Code nodes for cost calculations, Data Table integration for receipt storage, and Split in Batches for workflow processing. Uses n8n API credentials to access workflow and execution data. Requires a pre-configured DataTable called "execution_receipts" with specific columns for workflowid, executionid, receipt, created_at, and units. Workflows must be tagged with "agent" for automatic tracking. Includes CSV template for quick DataTable setup and sticky notes for configuration guidance.
Take control of your AI agent spending with automated cost tracking that turns invisible token burns into actionable budget insights.
