Skip to main content

LLM usage tracker & cost monitor with node-level analytics (v2)

Workflow preview

Workflow preview
100%
LLM usage tracker & cost monitor with node-level analytics (v2) preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

LLM Cost Monitor & Usage Tracker for n8n v2: Now it can read multiple types of LLM usages. Better dynamic approach for reading model usage. What This Workflow Does This workflow provides co...

Best for

  • Engineering automation workflows
  • Multimodal AI automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.n8n, n8n-nodes-base.executeworkflowtrigger, n8n-nodes-base.stickynote, n8n-nodes-base.set, n8n-nodes-base.code, n8n-nodes-base.stopanderror, n8n-nodes-base.if, n8n-nodes-base.merge

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Amir Safavi-Naini.

Original n8n.io source

1.1 Workflow description

Title
LLM usage tracker & cost monitor with node-level analytics (v2)
Workflow name
LLM usage tracker & cost monitor with node-level analytics (v2)

LLM Cost Monitor & Usage Tracker for n8n

> v2: Now it can read multiple types of LLM usages. Better dynamic approach for reading model usage.

🎯 What This Workflow Does

This workflow provides comprehensive monitoring and cost tracking for all LLM/AI agent usage across your n8n workflows. It extracts detailed token usage data from any workflow execution and calculates precise costs based on current model pricing.

The Problem It Solves

When running LLM nodes in n8n workflows, the token usage and intermediate data are not directly accessible within the same workflow. This monitoring workflow bridges that gap by:

  • Retrieving execution data using the execution ID
  • Extracting all LLM usage from any nested structure
  • Calculating costs with customizable pricing
  • Providing detailed analytics per node and model
  • WARNING: it works after the full execution of the workflow (i.e. you can't get this data before completion of all tasks in the workflow)

βš™οΈ Setup Instructions

Prerequisites

  1. Experience Required: Basic familiarity with n8n LLM nodes and AI agents
  2. Agent Configuration: In your monitored workflows, go to agent settings and enable "Return Intermediate Steps"
  3. For getting execution data, you need to set upthe n8n API in your instance (also available onthe free version)

Installation Steps

  1. Import this monitoring workflow into your n8n instance
  2. Go to Settings >> select n8n API from left bar >> define an API. Now you can add this as the credential for your "Get an Execution" node
  3. Configure your model name mappings in the "Standardize Names" node
  4. Update model pricing in the "Model Prices" node (prices per 1M tokens)
  5. To monitor a workflow:
    • Add an "Execute Workflow" node at the end of your target workflow
    • Select this monitoring workflow
    • Important: Turn OFF "Wait For Sub-Workflow Completion"
    • Pass the execution ID as input

πŸ”§ Customization

When You See Errors

If the workflow enters the error path, it means an undefined model was detected. Simply:

  1. Add the model name to the standardize_names_dic
  2. Add its pricing to the model_price_dic
  3. Re-run the workflow

Configurable Elements

  • Model Name Mapping: Standardize different model name variations (e.g., "gpt-4-0613" β†’ "gpt-4")
  • Pricing Dictionary: Set costs per million tokens for input/output
  • Extraction Depth: Captures tokens from any nesting level automatically

πŸ“Š Output Data

Per LLM Call

  • Cost Breakdown: Prompt, completion, and total costs in USD
  • Token Metrics: Prompt tokens, completion tokens, total tokens
  • Performance: Execution time, start time, finish reason
  • Content Preview: First 100 chars of input/output for debugging
  • Model Parameters: Temperature, max tokens, timeout, retry count
  • Execution Context: Workflow name, node name, execution status
  • Flow Tracking: Previous nodes chain

Summary Statistics

  • Total executions and costs
  • Breakdown by model type
  • Breakdown by node
  • Average cost per call
  • Total execution time

✨ Key Benefits

  • No External Dependencies: Everything runs within n8n
  • Universal Compatibility: Works with any workflow structure
  • Automatic Detection: Finds LLM usage regardless of nesting
  • Real-time Monitoring: Track costs as workflows execute
  • Debugging Support: Preview actual prompts and responses
  • Scalable: Handles multiple models and complex workflows

πŸ“ Example Use Cases

  • Cost Optimization: Identify expensive nodes and optimize prompts
  • Usage Analytics: Track token consumption across teams/projects
  • Budget Monitoring: Set alerts based on cost thresholds
  • Performance Analysis: Find slow-running LLM calls
  • Debugging: Review actual inputs/outputs without logs
  • Compliance: Audit AI usage across your organization

πŸš€ Quick Start

  1. Import workflow
  2. Update model prices (if needed)
  3. Add monitoring to any workflow with the Execute Workflow node
  4. View detailed cost breakdowns instantly

Note: Prices are configured per million tokens. Default includes GPT-4, GPT-3.5, Claude, and other popular models. Add custom models as needed.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Get an execution

Type / Role
n8n-nodes-base.n8n - n8n
Config choices
Version 1

Block 2 - When Exc.

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 3 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - model prices

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 6 - Standardize names

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 7 - Check correctly defined

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 8 - Stop and Error

Type / Role
n8n-nodes-base.stopAndError - stopAndError
Config choices
Version 1

Block 9 - If not passed

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 10 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.2

Block 11 - Calculate cost

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 12 - Test id

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 13 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Find Nodes with LLM Use

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 18 - create models_used list

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

3. Summary Table

Workflow LLM usage tracker & cost monitor with node-level analytics (v2)
Complexity advanced
Nodes 18
Categories Engineering, Multimodal AI
Author Amir Safavi-Naini
Published 14 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7398/7398.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does LLM usage tracker & cost monitor with node-level analytics (v2) do?

LLM Cost Monitor & Usage Tracker for n8n v2: Now it can read multiple types of LLM usages. Better dynamic approach for reading model usage. What This Workflow Does This workflow provides co...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, Multimodal AI use case.