Overview
The AI Token Tracking node is designed to monitor and analyze token usage in AI language model workflows. It tracks input and output tokens during AI interactions, enabling users to gather detailed usage statistics for monitoring, cost management, or optimization purposes. Additionally, it can optionally forward token tracking data to a specified sub-workflow for further processing or custom handling.
Common scenarios:
- Monitoring token consumption in AI-powered chatbots or assistants to control costs.
- Collecting usage metrics for reporting or auditing AI model interactions.
- Integrating with downstream workflows that perform analytics or alerting based on token usage.
Practical example:
A user connects an AI language model node to this token tracking node. As the workflow runs, the node records token usage per session and optionally sends this data to a sub-workflow that aggregates usage statistics and triggers notifications if thresholds are exceeded.
Properties
| Name | Meaning |
|---|---|
| Sub-Workflow (Optional) | Optional selection of a sub-workflow to which token tracking data will be sent automatically. If specified, token usage details are forwarded to this sub-workflow for additional processing. |
Output
The node outputs an array containing one object per input item with the following structure in its json field:
- All original input data fields are preserved.
- An additional
_aiTokenTrackingobject is added containing:sessionId: A unique identifier for the token tracking session.nodeId: The name of this token tracking node.workflowId: The current workflow's ID.trackingEnabled: Alwaystrue, indicating token tracking is active.timestamp: ISO string timestamp when the tracking data was generated.- In case of errors, an
errorfield describing the failure.
This output serves as a passthrough of the AI model data enriched with token tracking metadata.
Dependencies
- Requires connection to an AI language model node as input.
- Optionally requires configuration of a sub-workflow to receive token tracking data.
- Uses internal helper modules for token tracking, session ID generation, and sub-workflow execution.
- No external API keys or environment variables are explicitly required by this node itself, but the connected AI model node may require authentication credentials.
Troubleshooting
Error: "No AI model connected"
This error occurs if the node does not detect a connected AI language model input. Ensure that the AI model node is properly connected to this nodeβs input before execution.Failure sending data to sub-workflow
If the optional sub-workflow is specified but fails to receive token data, an error message is logged to the console. Check that the sub-workflow ID is correct and that the sub-workflow is active and accessible.Token tracking data missing or incomplete
Verify that the AI model node supports token usage reporting and that the workflow is correctly passing data through this node.