Track LLM token spend per workflow with n8n API, data tables, and Slack alerts
Quick overview This workflow runs every 15 minutes, pulls recent n8n executions via the n8n API, calculates per-call LLM token costs, stores them in an n8n Data Table, and posts a Slack alert when any workflow exceeds its daily budget (optionally deactivating the workflow).
How it works Runs every 15 minutes on a schedule. Retrieves the latest active-workflow executions (including execution details) from the n8n API. Extracts each chat model call from the execution run data, reads stored token usage (or estimates), matches the model to a price list, and calculates a USD cost per call. Checks an n8n Data Table to skip LLM calls that have already been logged, then inserts only new usage rows. Reads today’s rows from the Data Table, totals spend per workflow, and identifies workflows that exceed their configured daily budget while ensuring only one alert per workflow per day. Optionally deactivates over-budget workflows via the n8n API, then sends a budget-overrun message to a Slack channel.
Setup Create an n8n API key and add an n8n API credential, then select it in the n8n nodes used to list executions and deactivate workflows. Create an n8n Data Table with the required columns (including callKey, workflowId, token counts, costUsd, and finishedAt) and select the table in all Data Table nodes. Connect a Slack credential and choose the target channel for alerts. Update the configuration values for pricesPer1M, dailyBudgetUsd, budgetOverrides, and pauseOverBudget to match your models, budgets, and desired behavior.
Requirements n8n API access (self-hosted, or a Cloud plan that includes the API), Data tables, Slack.
Customization Change the interval, raise Limit in Get recent executions if you run more than 100 executions per interval, or send the alert by email instead of Slack.
Additional info A row is marked estimated when the provider returned no usage and n8n stored its own estimate. On n8n 2.43 the OpenAI Chat Model node with Use Responses API switched on stores only the estimate. Switch it off for exact counts.
Related Templates
Transform Gmail Newsletters into Insightful LinkedIn Posts Using OpenAI
Who Is This For? This workflow is perfect for content creators, marketers, and business professionals who receive regu...
Subscribe to new releases of a Github repository via Gmail
This is a very simple workflow that lets you subscribe to any github repository for the latest release (using n8n as ex...
AI Email Classifier & Auto-Delete for Gmail (SPAM/OFFER Cleaner)
This workflow is designed for freelancers, solopreneurs, and business owners who receive a high volume of irrelevant mes...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments