Track tokens

Hi everyone!

I’m trying to implement AI Agent logging in n8n based on this tutorial:

https://youtu.be/vVdS-ZEFf50?si=eFIw-W-PDVrfZb0b&t=157

Even though I’ve enabled the ‘Return Intermediate Steps’ option, the output still only returns the basic response. The detailed token usage and intermediate steps aren’t appearing in the output data at all.

Has anyone else encountered this issue? Is there a specific expression or perhaps an additional Code node required to properly extract these JSON fields?

Thanks for the help!

1 Like

Hi @tiboo Welcome to the community!
The video of nate herk is nice but that version of n8n is very old and currently n8n does not fully expose that token data into the output of the AI agent, what i have done is that:

  • Turn save execution progress (In the workflow settings) on so that it saves everything.
  • And to get that current execution ID you can use this expression {{$execution.id}}
  • Then just call the n8n API of executions using HTTP request , with that ID to get complete execution data and there might be some field like tokenUsage.

Like this might sound lengthy but is pretty much easy if once settled up!
And you can read this for more clear approach:

or if you want something like an estimator this has already been created

Thanks a lot man, thanks a lot, working now.

Yeah the execution API approach is really the only reliable way to get token data right now, the AI Agent node just doesn’t surface it properly in the output even with intermediate steps on. If you want something more structured there’s a community workflow called Token Estim8r that automates the whole thing and logs costs to Google Sheets, worth checking out.

@tiboo Glad it helped, kindly mark that as a solution! Cheers!