Monitor Your LLM Costs: n8n AI Token Usage Tracker
detail.loadingPreview
This workflow provides a robust solution for tracking and analyzing token usage from your AI-powered n8n workflows. Gain clarity on your Large Language Model (LLM) costs by automatically extracting and summarizing prompt and completion token data for each model used.
About This Workflow
Understanding the expenditure of your AI workflows is crucial for budget management and optimization. This n8n workflow addresses that challenge by offering a comprehensive system to monitor token usage from your Langchain AI Agent nodes. It intelligently retrieves execution details via the n8n API, parses out model-specific token consumption, and aggregates it for a clear overview. Designed to run as a sub-workflow, it ensures efficient data retrieval without impacting your primary workflow's performance, providing valuable insights into your LLM operational costs.
Key Features
- Automated Token Extraction: Automatically captures prompt and completion token usage from your AI Agent nodes.
- Model-Specific Aggregation: Summarizes token totals, grouped by the specific AI models used in your workflows.
- Seamless n8n API Integration: Leverages the n8n API to fetch detailed execution data, ensuring accurate tracking.
- Langchain AI Agent Compatibility: Built to work directly with n8n's Langchain AI Agent for broad applicability.
- Efficient Sub-Workflow Design: Optimizes data retrieval by calling itself as a sub-workflow, preventing execution bottlenecks.
How To Use
- Set Up n8n API Credentials: Ensure you have an n8n API credential configured for the 'Get execution data' node to access workflow execution logs.
- Integrate the 'Call sub-workflow' Node: In your main workflow (where the AI Agent is located), add the 'Call sub-workflow' node at the end. Make sure its
workflowIdparameter points to the ID of this workflow andWait For Sub-Workflow Completionis disabled. - Run Your Main AI Workflow: Execute your primary workflow containing the AI Agent. The 'Call sub-workflow' node will automatically trigger this token tracking workflow in the background.
- Review Token Usage Data: After execution, this workflow will process and aggregate the token usage. You can inspect the output of the 'Sum Token Totals' node in the execution logs for a breakdown by model.
- Understand Limitations: Be aware that the cost estimates might be higher than actual due to prompt caching and that this workflow hasn't been tested with audio/video files.
Apps Used
Workflow JSON
{
"id": "98125d3d-9424-4150-9b36-b6e1856f2532",
"name": "Monitor Your LLM Costs: n8n AI Token Usage Tracker",
"nodes": 20,
"category": "Operations",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 98125d3d-9424...
About the Author
Crypto_Watcher
Web3 Developer
Automated trading bots and blockchain monitoring workflows.
Statistics
Related Workflows
Discover more workflows you might like
Google Sheets to Icypeas: Automated Bulk Domain Scanning
This workflow streamlines the process of performing bulk domain scans by integrating your Google Sheets data directly with the Icypeas platform. Automate the submission of company names from your spreadsheet to Icypeas for comprehensive domain information, saving valuable time and effort.
Instant WooCommerce Order Notifications via Telegram
When a new order is placed on your WooCommerce store, instantly receive detailed notifications directly to your Telegram chat. Stay on top of your e-commerce operations with real-time alerts, including order specifics and a direct link to view the order.
On-Demand Microsoft SQL Query Execution
This workflow allows you to manually trigger and execute any SQL query against your Microsoft SQL Server database. Perfect for ad-hoc data lookups, administrative tasks, or quick tests, giving you direct control over your database operations.