We Need Your Help! (Inconsistent Token Counting in “AI Agent”]

The AI Agent node is failing to consistently report token usage when Return Intermediate Steps is enabled. The tokenUsage object is missing for the final step of the agent’s process, and no token data is returned at all for single-step interactions. This prevents accurate cost tracking.

I am providing the exact JSON outputs from my workflow to demonstrate the issue.

What is the error message (if any)?

There is no error message. The problem is missing data in the final JSON output of the node.

Please share your workflow:

Share the output returned by the last node

Here are the actual outputs from my executions, which show the missing data.

Output A: Resultado com apenas UMA interação

As you can see, the intermediateSteps array is empty, providing no token information.

{
  "intermediateSteps": [],
  "finalOutput": "..."
}

This is the last object inside the intermediateSteps array returned by the n8n node. It shows the observation passed to the final LLM call, but the corresponding tokenUsage object for this step is missing.

{
  "intermediateSteps": [
    { "...passos anteriores..." },
    {
      "tool_call": {
        "name": "...",
        "args": { "..."},
        "id": "...",
        "type": "tool_call",
        "content": [
          {
            "text": {
              "content": [
                {
                  "text": { ... },
                  "id": "msg_01Totrs2a2T1WXgCSGzXi7Qt",
                  "invalid_tool_calls": []
                }
              ]
            },
            "observation": "Perfeito! Agora tenho todos os dados. Vejo que há dados de MAI/2025 (maio/2025) com valores.\n\nPreciso filtrar apenas os dados de MAI/2025 e ordenar por R$ Fat. Liquido para pegar os TOP 5:\n\nDados de MAI/2025:\n1. STHEFANIE CARES - 388.877,65\n2. FABIO RODRIGUES - 320.229,10\n3. GUILHERME PEREIRA - 320.546,72\n4. SAULO GONCALVES - 302.447,06\n5. MARCELUS WAGNER - 291.195,46\n[...]\n\nVou apresentar de forma clara e objetiva."
          }
        ]
      }
      // O OBJETO "tokenUsage" ESTÁ FALTANDO AQUI
    }
  ],
  "finalOutput": "**Top 5 Representantes – Maio/2025** 🏆..."
}

These are the internal logs from the LLM calls for that same execution. There were four calls in total. The tokenUsage object from the 4th call is the one that is missing from the n8n node’s output above.

Call 1:

{
  "response": { "generations": [[{ "text": "" }]] },
  "tokenUsage": { "completionTokens": 341, "promptTokens": 10250, "totalTokens": 10591 }
}

Call 2:

{
  "response": { "generations": [[{ "text": "" }]] },
  "tokenUsage": { "completionTokens": 310, "promptTokens": 10953, "totalTokens": 11263 }
}

Call 3:

{
  "response": { "generations": [[{ "text": "" }]] },
  "tokenUsage": { "completionTokens": 478, "promptTokens": 16175, "totalTokens": 16653 }
}

Call 4 (The missing token count):

{
  "response": {
    "generations": [
      [
        {
          "text": "**Top 5 Representantes – Maio/2025** 🏆\n\n**1.** STHEFANIE CARES → **R$ 388,9 mil** (66% da meta)  \n**2.** GUILHERME PEREIRA → **R$ 320,5 mil** (74% da meta)  \n**3.** FABIO RODRIGUES → **R$ 320,2 mil** (95% da meta)  \n**4.** SAULO GONCALVES → **R$ 302,4 mil** (94% da meta)  \n**5.** MARCELUS WAGNER → **R$ 291,2 mil** (130% da meta) 🔥  \n\n💡 **Destaque:** Marcelus Wagner foi o único que ultrapassou 100% da meta!  \nQuer ver os 5 menores resultados ou comparar com outro período?\n\n---\n\n*O Marcelus tá voando baixo, mas vendendo alto! 🚀* 😄"
        }
      ]
    ]
  },
  "tokenUsage": {
    "completionTokens": 253,
    "promptTokens": 17093,
    "totalTokens": 17346
  }
}

Information on your n8n setup

  • n8n version: 1.114.2

  • Database (default: SQLite): Managed by n8n Cloud

  • n8n EXECUTIONS_PROCESS setting (default: own, main): Managed by n8n Cloud

  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud

  • Operating system: n8n Cloud Environment

This makes it very difficult and inconsistent to track token use for AI Agent nodes that don’t use Tools (even if they are configured with tools).

The intermediate steps only output the Tool use.

It would be very helpful if there was a simple setting for an AI Agent node that would always output token use as well as the node output.

Good point — this makes token tracking pretty unreliable at the moment.
Do you happen to know if there’s any method or workaround to log the token usage correctly for AI Agent nodes (even when Tools aren’t used), or if this isn’t supported yet?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.