AI LLM Usage and Cost Tracking Dashboard Generator - n8n Workflow

Track and visualize large language model (LLM) usage metrics, tokens, and costs using this powerful n8n workflow. Generate an interactive HTML dashboard for real-time AI monitoring.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI Operations Teams: Who need to monitor the performance, traffic, and cost efficiency of their deployed LLM agents.
Developers and Engineers: Implementing AI solutions who require detailed usage logging for optimization and billing.
Business Managers: Seeking transparency into AI expenditure to control budget and forecast costs.
n8n Automation Specialists: Looking for advanced n8n templates demonstrating data processing, execution lookups, and dynamic HTML generation.

Overview

Managing the costs associated with Large Language Models (LLMs) is crucial for scalable AI applications. This comprehensive n8n workflow provides an end-to-end solution for collecting, processing, and visualizing detailed usage metrics, including prompt tokens, completion tokens, and estimated monetary cost.

This is one of the essential n8n templates for observability. It operates in two parallel modes: first, it logs every chat conversation in real-time. Second, a scheduled cleanup process uses the powerful n8n node to retrieve execution details, extracting precise token counts, and calculates the total cost based on pre-defined model pricing. Finally, a dedicated webhook generates a dynamic, interactive HTML dashboard featuring key performance indicators (KPIs) like total messages, unique sessions, total costs, and daily usage graphs, providing instant clarity into your AI automation expenditure.

How it Works

This n8n workflow is structured into three distinct execution paths:


  1. AI Chat Logging (Real-Time): The flow starts with the When chat message received n8n trigger. This immediately routes the input to the AI Agent (using the OpenAI Chat Model n8n node and Simple Memory for context). Upon receiving the response, the flow proceeds to the Get Execution ID node, which captures the current execution ID. The Insert row2 Data Table n8n node then logs the chat input, output, session ID, and the crucial execution ID for later token retrieval.


  1. Token and Cost Calculation (Scheduled): A Schedule Trigger fires every 30 minutes to clean up and enrich data. The flow uses the Get row(s) Data Table n8n node to find conversation entries lacking token/cost data. The Loop Over Items node then iterates through these records. For each item, the Get an execution n8n node retrieves the full execution history using the stored ID. The Model/Token Info node extracts the token metrics directly from the run data of the OpenAI Chat Model n8n node. This data is merged (Merge1) with model pricing fetched from a separate Data Table, and the Code in JavaScript1 node computes the final globalCost. The Update row(s) Data Table node completes the cycle by writing the calculated tokens and costs back to the conversation record.


  1. Dashboard Generation (On-Demand): An external Webhook n8n trigger is used to generate the dashboard view. The workflow retrieves all conversation data (Get row(s)1) and passes it to the highly customized Code in JavaScript n8n node. This node processes all historical data, calculates aggregated KPIs (averages, totals, daily counts), and dynamically generates a responsive HTML page embedding Chart.js visualizations. The final output is returned via the Respond to Webhook n8n node, displaying the live monitoring dashboard.

Installation Guide

To deploy this powerful n8n workflow template, follow these steps:


  1. Import: Import the provided JSON into your n8n instance.

  2. Credentials: Configure credentials for the Langchain nodes (if needed) and ensure you have an n8n API credential set up for the Get an execution n8n node. This credential must have permissions to read execution data.

  3. Data Tables: Create two Data Tables within your n8n project:

Table 1 (Messages): Used by Insert row2, Get row(s), Get row(s)1, and Update row(s). Ensure columns like sessionId, executionId, completionTokens, promptTokens, totalTokens, globalCost, and modelName exist.
Table 2 (Model - Price): Used by Get row(s)3. This table must store the pricing information (name, promptTokensPrice, completionTokensPrice) for your specific LLM models (e.g., 'gpt-4o', 'gpt-4.1-mini').

  1. Pricing Setup: Use the Edit Fields1 and Insert row1 nodes to quickly populate your Model Pricing table with the costs per 1,000 tokens for each model you intend to track. The workflow includes example data for various models.

  2. Activation: Ensure all parts of the n8n workflow are active. The scheduled maintenance will run automatically, and the dashboard is accessible via the main Webhook n8n trigger URL.

Node Details

When chat message received (Langchain Chat Trigger): The starting n8n trigger for all AI interactions. Configured to listen for incoming chat messages.
AI Agent (Langchain Agent): Executes the LLM logic, generating a response using the connected Language Model.
OpenAI Chat Model (Langchain Language Model n8n node): Specifies the LLM model used (e.g., gpt-4.1-mini) and requires OpenAI API credentials. This node's execution metrics contain the token usage data.
Get an execution (n8n node): Crucial for retrieving internal metrics. It uses the executionId logged earlier to fetch the complete execution data, allowing access to token usage metrics that are finalized post-execution.
Insert row2 / Get row(s) / Update row(s) (Data Table n8n node): Handles persistence. Used to store conversation metadata, look up unprocessed records, and update those records with calculated token metrics and costs.
Model/Token Info (Set n8n node): Extracts the specific token counts (promptTokens, completionTokens) from the execution data returned by the previous n8n node.
Code in JavaScript (Code n8n node): The core of the dashboard generator. Aggregates data from the Data Table, computes KPIs, and generates the entire interactive HTML (including embedded Chart.js for data visualization).
Webhook (n8n trigger): Provides a public endpoint to instantly generate and view the monitoring dashboard.

Related n8n Workflows

Free

Nodes: 15 Nodes
Updated: December 26 2025
View all
Created by
Hugo
Hugo

Growth engineer focused on AI, data automation, and custom integrations. Use to turn complex ideas into simple, and scalable workflows with solid infrastructure

Featured*