Templates / Track OpenAI token usage and AI agent metrics with Google Sheets dashboard

Track OpenAI token usage and AI agent metrics with Google Sheets dashboard

Needs changes

by Hunyao ✓ · 1,278 views · created 2025-08-11 · Engineering, Multimodal AI

Needs changes. This template uses 1 thing(s) that n8n 3.0 removes: LangChain Code (legacy). 1 breaking item(s) found. Static check, last run 2026-10-19.

What to replace before upgrading

Removed in 3.0Replace with
LangChain Code (legacy)
LangChain Chat Model + Token Callback
No direct replacement

Nodes used (7)

AI AgentGoogle SheetsLangChain Code

What it does

What it does Captures token usage and cost from your AI Agent/LLM. Logs model, tokens, cost, tool use, and conversation I/O to Google Sheets for simple observability and billing. Perfect for Developers adding usage monitoring to AI agents. Teams needing cost transparency in prototypes. How it works 1. Chat Trigger collects user input for the AI Agent. 2. A Set node injects metadata like workflow, execution, and client IDs. 3. LangChain Code node returns a configured Chat model with a callback that reads usage metadata. 4. The callback computes input, output, and total costs based on per‑million token prices you define. 5. It appends token metrics to a Google Sheet via the Google Sheets Tool. 6. The Agent records intermediate tool calls. 7. An If node checks whether a tool was used. 8. When tools are used, the workflow logs input, output, tool name, and metadata to an Observability sheet. How to use SELF-HOSTED N8N ONLY - the Langchain Code node is only available in the self-hosted version of n8n. It is not available in n8n cloud. Requirements Self-hosted version of n8n If you have any questions in running the workflow, see the attached video: https://youtu.be/JSulRS128MA

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.