Add token usage output to AI Agent and Chat Model subnodes

The idea is:

Add token usage output (input tokens, output tokens, total tokens) to the AI Agent node and Chat Models subnode, exposing these values as referenceable fields in subsequent nodes.

My use case:

I’m building an AI-powered SaaS with usage-based billing. I need to:
Track exact token consumption per user request
Store token usage in my database for billing calculations
Calculate costs dynamically based on model-specific pricing
Display real-time usage to users
Currently I have to estimate or use external API calls to get this data.

I think it would be beneficial to add this because:

1- Billing accuracy - SaaS builders need precise token counts for usage-based pricing
2- Cost monitoring - Track spending across different AI models
3- Workflow optimization - Identify expensive prompts and optimize them
4- Native solution - Avoids workarounds like separate API calls or middleware

Any resources to support this?

OpenAI API returns usage object with prompt_tokens, completion_tokens, total_tokens
Anthropic returns usage with input_tokens, output_tokens
Google Gemini returns usageMetadata with token counts
All major LLM providers already return this data - n8n just needs to expose it.

Are you willing to work on this?

Yes, happy to test and provide feedback.

Welcome Back @Mohamed_Khalaf,

Currently, n8n doesn’t expose token usage (input/output/total) as first‑class fields on the AI Agent or chat model nodes.

Workarounds:

  • Disable “Simplify Output” on the nodes to see token info in raw responses.
  • Pull execution data via the n8n API and read tokenUsage from the JSON.

Future: No native field for token usage yet, but it aligns with ongoing features for AI metrics.

For now, use these workarounds for precise tracking. What i think is that you could use CodeNode to validate and count tokens or in the AI prompt specify that the AI should include Incoming/Ongoing tokens so with that you can extract those data from the response alongside your AI output and then you can save it, like this can be done and would be better to use a code node to validate input/output using javascript. Let me know if this helps!

1 Like