Solved ✅ - How to Get LLM Token Usage from AI Agents

,

Hey community! :wave:

I’ve been trying to find a way to get accurate Tokens used counts for a while and I’ve seen a few questions lately on how to track token usage and cost in the community so I built Token Estim8r, a plug-and-play workflow you can hook into any other workflow using a simple HTTP Request at the end and get accurate token usage and costs added to a google sheet as well as individual breakdown in the JSON Array column.

click here to see the template on n8n Token Estim8r


Image Generated with ideoGener8r n8n workflow template


This makes it super easy to:

  • :white_check_mark: Automatically log token usage
  • :moneybag: See how much each workflow execution costs
  • :chart_with_upwards_trend: Store results in a Google Sheet
  • :repeat: Reuse across any workflow with just a webhook

:wrench: What This Workflow Does

  • Accepts an execution ID via webhook
  • Fetches execution details using n8n’s internal API
  • Parses which models/tools were used and how many tokens
  • Calculates the cost (with optional live pricing via Jina)
  • Logs everything to a Google Sheet

:hammer_and_wrench: Setup Guide

1. Copy and import this CSV into Google Sheets:

timestamp, Workflow Name, Workflow ID, Workflow Execution Id, Total Tokens, Prompt Tokens, Completion Tokens, Models Used, Tools Used, Total Cost, Json Array

2. Open the Token Estim8r workflow

  • Set your Google Sheet credentials
  • Optional: Set up your Jina API key in the Get AI Pricing node for live pricing

3. Add a Webhook Trigger node to your Token Estim8r workflow

  • This is the URL you’ll call from any other workflow

4. In your main workflow, add an HTTP Request node at the end:

  • Method: POST
  • URL: the webhook from step 3
  • Body: {"executionId": "{{$execution.id}}"}

5. Run your workflow and check the sheet! :tada:


:brain: Why This Is Useful

  • Helps understand cost per feature or action in your app
  • Makes budgeting OpenAI or Claude usage easier
  • Helps detect runaway token use or prompt errors

:memo: Sticky Note Preview

This workflow receives an executionId and calculates the token usage + cost for LLM calls made during that run. It logs the results into a Google Sheet. Optional: Enable live pricing via Jina.

:arrows_counterclockwise: Customize It

  • Change the logging destination (Notion, Airtable, DB)
  • Add Slack alerts when a run costs too much
  • Group weekly or monthly usage by workflow

Let me know if you’d like a version that logs to Airtable or Notion, or if youd like a UI Dashboard to see all your flows token usage. :rocket:

Big thanks to everyone who’s been asking for this, hoping it saves you time and :money_mouth_face: money :raised_hands:

3 Likes

Thank you very much, that’s exactly what I needed.