Token usage data is missing after "Basic LLM Chain" node

Hi,

I am using the Google Gemini Chat Model with the Basic LLM Chain.

In the Gemini node output, I can see the tokenUsage data (prompt, completion, and total tokens). However, in the next node (Set or Code node), this data disappears. Only the text is passed through.

What I’ve tried:

  • Checked {{ $json.tokenUsage.totalTokens }} → Returns undefined.

  • Removed all Output Parsers → Still no token data.

  • Tried a Code node to find the data → It’s not there.

Screenshot 1: Shows Gemini node has the token data. Screenshot 2: Shows the next node says the data is undefined.

How can I get the Basic LLM Chain to pass the token usage metadata to the next node? I need this for cost tracking.

Hi @Kunwei_TAN, welcome!
Currently this is a limitation with the basic LLM Chain node.
There is a possible workaround by using the AI agent node or by retrieving data by the N8N API.

If you want that kind of information directly, consider using the OpenAI node or Gemini node.

If you want to get the usage by the n8n API, here is the workaround: