Token tracking added to AI node telemetry
n8n workflows can now report AI token consumption per node to telemetry, giving visibility into how many tokens each AI interaction uses.
Workflow automation platform n8n now tracks how many AI tokens flow through each node. The change adds ai_input_tokens and ai_output_tokens fields to node graph telemetry, giving visibility into AI model token consumption alongside the existing AI model identifier.
Two categories of AI nodes are covered: language model sub-nodes connected to agents and chains, which already had standardized token data available via N8nLlmTracing; and standalone vendor nodes including OpenAI, Anthropic, Ollama, and Google Gemini, which capture token usage directly from API responses before the "Simplify output" step strips it away.
A shared accumulateTokenUsage utility in the n8n-workflow package handles accumulation across multi-item executions and keeps vendor node changes minimal—a single function call at each token-capture point.
This is part of a broader initiative to improve AI observability in n8n workflows.
View Original GitHub Description
Summary
Add ai_input_tokens and ai_output_tokens fields to node_graph_string telemetry, alongside the existing ai_model field. This enables tracking AI model token consumption per node in Metabase.
Two categories of AI nodes are covered:
-
LM sub-nodes (e.g.
lmChatOpenAi, connected to Agents/Chains) — token data is already standardized viaN8nLlmTracing, extracted directly fromrunDataand summed across agent multi-call scenarios. -
Standalone vendor nodes (defined in
AI_VENDOR_NODE_TYPES: OpenAI, Anthropic, Ollama, Google Gemini) — token data comes from raw API responses but is normally stripped by the "Simplify output" default. We capture it viasetMetadata()before simplification, preserving it for telemetry without affecting user-visible output.
A shared accumulateTokenUsage() utility in n8n-workflow handles accumulation across multi-item executions and keeps vendor node changes to a one-liner.
How to verify: Run a workflow with any AI node, check that node_graph_string in the telemetry event includes ai_input_tokens and ai_output_tokens for the AI node entries.
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/NODE-4781
Review / Merge checklist
- PR title and summary are descriptive. (conventions)
- Docs updated or follow-up ticket created.
- Tests included.
- PR Labeled with
release/backport(if the PR is an urgent fix that needs to be backported)