Track AI Agent token usage and estimate costs in Google Sheets
VerifiedTrack AI agent token usage and estimate costs in Google Sheets.
What this workflow does
This workflow captures token usage from AI agents via execution metadata and stores results in Google Sheets for automated cost estimation using spreadsheet formulas.
It is designed for developers and teams running AI agents who need to monitor LLM consumption and expenses across multiple providers.
Who is this for?
AI engineers, automation teams, and product builders running LLM agents in n8n who need visibility into spend.
What problem it solves
AI Agents do not expose full token counts from tool calls, making accurate usage tracking and cost estimation difficult without manual work.
Live workflow preview
Interactive canvas of every node and connection — scroll and click to explore. Powered by n8n's preview.
Open the template on n8n to import and run it. View source template →
What it automates
Monthly LLM budget review
Log every agent run to a shared Google Sheet so finance can see real token totals and estimated costs across OpenAI, Anthropic, and Gemini.
Agent optimization sprint
Compare token usage before and after prompt changes by routing the same agent through the subworkflow and reviewing the spreadsheet formulas.
Client project billing
Store per-execution data with project tags so invoices can be generated from the calculated cost column in Sheets.
How the workflow works
The 6 nodes in this automation, in order.
- 1Google SheetsgoogleSheets
- 2AI Agent@n8n/n8n-nodes-langchain.agent
- 3Anthropic Chat Model@n8n/n8n-nodes-langchain.lmChatAnthropic
- 4OpenAI Chat Model@n8n/n8n-nodes-langchain.lmChatOpenAi
- 5Google Gemini Chat Model@n8n/n8n-nodes-langchain.lmChatGoogleGemini
- 6Think Tool@n8n/n8n-nodes-langchain.toolThink
Apps & integrations used
How to set up Track AI Agent token usage and estimate costs in Google Sheets
- 1Import the template into your n8n instance and connect Google Sheets and LLM credentials.
- 2Replace the example AI Agent with your own agent or keep it for testing.
- 3Ensure the subworkflow is called only after all other branches finish.
- 4Add your n8n API key so the subworkflow can read execution metadata.
- 5Open the linked Google Sheet and verify the cost-calculation formulas reference the incoming token columns.
- 6Run a test execution and confirm a new row appears with token counts and estimated cost.
How to customize this workflow
- →Swap the Chat Model node between OpenAI, Anthropic, or Google Gemini without changing the rest of the flow.
- →Add a project or user ID field before the Sheets node to segment costs.
- →Insert an extra Think Tool step if you need custom token parsing for a new provider.
- →Change the trigger from manual to a schedule or webhook to run cost tracking automatically.
Track AI Agent token usage and estimate costs in Google Sheets: pros & cons
Pros
- +Pulls accurate token data from execution metadata instead of incomplete agent output
- +Works out of the box with OpenAI, Anthropic, and Gemini
- +Cost formulas live in Google Sheets so anyone can edit or extend them
- +Subworkflow pattern keeps the main agent flow clean
Cons
- –Requires an n8n API key and subworkflow call after every agent run
- –Other LLM providers may need small parsing tweaks
- –Spreadsheet formulas must be maintained if pricing changes
Frequently asked questions
It captures token usage from AI Agent executions via workflow metadata, writes the data to Google Sheets, and uses spreadsheet formulas to estimate cost.
User reviews
Verified reviews from the community shape this listing's rating.
Loading reviews…