Retrieve LLM Token Usage in AI Agents

Here’s a workaround:

You can use an n8n: Get Execution node with the “Include Execution Details” option enabled.

This will retrieve information about the entire execution, including Chat Model usage details in the following format:

{
  "tokenUsage": {
    "completionTokens": <number>,
    "promptTokens": <number>,
    "totalTokens": <number>
  }
}

Therefore, you can set up a separate workflow that you can trigger with the execution ID after your AI Agent workflow completes.

It might sound a bit cumbersome, but it should do the trick.

7 Likes