Track AI agent token usage and estimate costs in Google Sheets
Needs changesNeeds changes. This template uses 1 thing(s) that n8n 3.0 removes: AI Agent v1 (old agent modes). 1 breaking item(s) found. Static check, last run 2026-10-19.
What to replace before upgrading
| Removed in 3.0 | Replace with |
|---|---|
| AI Agent v1 (old agent modes) AI Agent (v1.8) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (13)
- Manual Trigger
n8n-nodes-base.manualTrigger - AI Agent
@n8n/n8n-nodes-langchain.agent - Execute Sub-workflow
n8n-nodes-base.executeWorkflow - Think Tool
@n8n/n8n-nodes-langchain.toolThink - Edit Fields (Set)
n8n-nodes-base.set - n8n
n8n-nodes-base.n8n - Execute Workflow Trigger
n8n-nodes-base.executeWorkflowTrigger - Split Out
n8n-nodes-base.splitOut - Summarize
n8n-nodes-base.summarize - Google Sheets
n8n-nodes-base.googleSheets - Google Gemini Chat Model
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - Anthropic Chat Model
@n8n/n8n-nodes-langchain.lmChatAnthropic
What it does
!image.png(fileId:1659) This n8n template demonstrates how to obtain token usage from AI Agents and places the data into a spreadsheet that calculates the estimated cost of the execution. Obtaining the token usage from AI Agents is tricky, because it doesn't provide all the data from tool calls. This workflow taps into the workflow execution metadata to extract token usage information. Works well with OpenAI, Google and Anthropic. Other LLM providers might need small tweaks. How it works 1. The AI Agent executes and then calls a subworkflow to calculate the token usage. 2. The data is stored in Google Sheets 3. The spreadsheet has formulas to calculate the estimated cost of the execution. How to use - The AI Agent is used as an example. Feel free to replace this with other agents you have. - Call the subworkflow AFTER all the other branches have finished executing. Requirements - LLM account (OpenAI, Gemini...) for API usage. - Google Drive and Sheets credentials - n8n API key of your instance