Note: This template only works for self-hosted n8n. This n8n template demonstrates how to use the Langchain code node to track token usage and cost for every LLM call. This is useful if your templates handle multiple clients or customers and you need a cheap and easy way to capture how much of your AI credits they are using. How it works In our mock AI service, we're offering a data conversion API to convert Resume PDFs into JSON documents. A form trigger is used to allow for PDF upload and the file is parsed using the Extract from File node. An Edit Fields node is used to capture additional variables to send to our log. Next, we use the Information Extractor node to organise the Resume data into the given JSON schema. The LLM subnode attached to the Information Extractor is a custom one we've built using the Langchain Code node. With our custom LLM subnode, we're able to capture the usage metadata using lifecycle hooks. We've also attached a Google Sheet tool to our LLM subnode, allowing us to send our usage metadata to a google sheet. Finally, we demonstrate how you can aggregate from the google sheet to understand how much AI tokens/costs your clients are liable for.
Tags
Related workflows
See all AI Automation→AI: Summarize podcast episode and enhance using Wikipedia
The workflow automates the process of creating a summarized and enriched podcast digest, which is then sent via email. Note that to use this template, you need to be on n8n version 1.19.4 or later.
Send and track Slack invoice requests with Gemini, Google Sheets and Gmail
Quick overview Youtube Video: https://youtu.be/42-oHh9w9Eo This workflow listens for Slack @mentions, uses Google Gemini to classify the request and extract invoice details, then reads and updates Google Sheets, generates invoice PDFs with PdfBro, sends invoices or reminders via Gmail, and posts confirmations or errors back to Slack. How it works Triggers when the workflow’s Slack app is mentioned in a specified Slack channel. Uses Google Gemini to classify the message intent (send invoice, remind invoice, or check status) and extract the recipient email and invoice due date. Routes the request based on the extracted intent and stops if the intent cannot be determined. For SEND_INVOICE, looks up the client in a Google Sheets “Client Bill” spreadsheet and posts a Slack error if no matching email is found. If a client is found, generates an invoice PDF with PdfBro, emails it to the client via Gmail, appends/updates the invoice record in a Google Sheets “Client Invoices” spreadsheet, and posts a Slack confirmation. For REMIND_INVOICE, finds an UNPAID invoice for the email in the “Client Invoices” Google Sheet, regenerates the invoice PDF with PdfBro, emails a reminder via Gmail, and p
Handle WhatsApp customer service chats with Google Gemini and Google Sheets
Quick Overview This workflow handles WhatsApp customer service via OpenWA, using Google Gemini and a Google Sheets knowledge base to answer personal chats, while routing conversations to a human queue in Google Sheets when escalation is needed. How it works Triggers on OpenWA WhatsApp events and ignores message reactions except for specific ✅/☑ reactions used to re-enable AI handling. Normalizes incoming event fields and processes only personal chats (IDs ending with @c.us) that are not sent by your own WhatsApp account. Checks a Google Sheets “Session Chat” list to decide whether the conversation is currently handled by a human, and only continues to AI when no active human session is found. Uses a Google Gemini chat model with short-term memory and a Google Sheets “Database Company” tool to draft a friendly Indonesian response based only on the sheet data. If the AI response does not contain the #admin escalation token, it sends the reply back to the customer via OpenWA. If the AI response contains #admin, it appends the chat to the Google Sheets “Session Chat” sheet to flag it for human follow-up. When a ✅/☑ reaction is received for a chat, it finds and deletes the corresponding