See llms.txt for all machine-readable content.

Back to Templates

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

  1. Runs every 15 minutes on a schedule.
  2. Retrieves the latest active-workflow executions (including execution details) from the n8n API.
  3. 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.
  4. Checks an n8n Data Table to skip LLM calls that have already been logged, then inserts only new usage rows.
  5. 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.
  6. Optionally deactivates over-budget workflows via the n8n API, then sends a budget-overrun message to a Slack channel.

Setup

  1. 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.
  2. 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.
  3. Connect a Slack credential and choose the target channel for alerts.
  4. 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.