Templates / Track LLM token costs per customer using the Langchain code node

Track LLM token costs per customer using the Langchain code node

Needs changes

by Jimleuk ✓ · 1,759 views · created 2025-04-05 · Engineering, AI Summarization

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 this workflow does

This AI workflow has 12 nodes and runs when someone submits an n8n form (“CV Parsing Service”) (plus 1 other trigger). Along the way it connects Google Sheets and Gmail.

How it runs

Trigger: When someone submits an n8n form (“CV Parsing Service”) (plus 1 other trigger).

  1. Parse PDF Upload (Extract from File): extracts data from a file (pdf)
  2. Get Client Logs (Google Sheets): uses Google Sheets
  3. Logging Attributes (Edit Fields (Set)): sets 3 fields: workflow_id, execution_id, client_id
  4. Filter: keeps only the items that match a condition
  5. Extract Resume Data (Information Extractor): extracts structured fields from text with AI, with model: Custom LLM Subnode
  6. Calculate Totals (Summarize): summarizes / groups the items
  7. Display JSON Document (n8n Form): shows the next form page
  8. Send Invoice (Gmail): uses Gmail

Services it uses

Google SheetsGmail

Before you upgrade to n8n 3.0

1 thing in this workflow is removed in n8n 3.0. Fix it before you upgrade:

  • LangChain Code (legacy) in Custom LLM Subnode: no direct replacement.

Rather not rewrite it? Many of these flows can be rebuilt in Make (free plan).

Removed in 3.0Replace with
LangChain Code (legacy)
Custom LLM Subnode
No direct replacement

Nodes used (12)

From the author

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…

Excerpt from Jimleuk's description on n8n.io.

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.