Track LLM Token Costs per Customer with Langchain Code Node

Track token usage and costs for every LLM call per customer using a custom Langchain Code node in self-hosted n8n. Logs data to Google Sheets for aggregation and billing insights.

n8n
Track LLM Token Costs per Customer with Langchain Code Node

This n8n workflow demonstrates tracking LLM token usage and costs for individual customers using the Langchain Code node, exclusively for self-hosted n8n instances. It simulates an AI service converting resume PDFs to JSON: a form trigger handles PDF uploads, followed by file extraction, field editing for metadata, and an Information Extractor node with a custom LLM subnode built via Langchain Code. Lifecycle hooks capture usage metadata, which is logged to Google Sheets.

Key benefits include cost transparency for multi-client AI services, enabling accurate billing based on token consumption without complex setups. It saves time on manual tracking and scales effortlessly for production use.

Use cases: AI agencies offering document processing APIs, customer support bots with LLM interactions, or any service charging per token. Aggregate sheet data to generate client reports, monitor budgets, and optimize LLM expenses. Example log sheet provided for reference.

$19.99
Last updated November 14, 2026
30-day money-back guarantee
Instant download
Lifetime updates included

New buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.

Secure checkout powered by Stripe

Support

How to import this workflow into n8n

  1. 1Purchase or download the workflow to get the n8n workflow JSON file.
  2. 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
  3. 3Open each node marked with a credential warning and connect your own accounts and API keys.
  4. 4Run the workflow once manually to verify the data flow, then toggle it to Active.

Related Customer Support workflows

More from Nadia Ivanov

Need this deployed? We'll set it up for you.

Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.