So basically one of my clients was asking if we could understand Tokens BEFORE sending data to the AI model. I looked everywhere and it seemed there are open source alternatives and aslo its all API its not just built into claude (Or at least I couldn’t find it), so then I said, WHY DONT I JUST BUILD ONE?
Using Claude Code I built out a full n8n workflow that works like this:
Shows a form to input your PROMPT and any FILES (PDFs, etc.)
It then gets you a full REPORT Estimating costs for various models AND all the data is within a google sheet so you can calibrate it by grabbing live data OR the API’s but other than that its self contained so you don’t actually use AI credits to figure it out every time (That was the API thing and that can suck tokens). I also made a webhook so you can access it via a Claude CLI as well just by sending a webhook and it will return JSON on the token estimate. Great to put in hooks into Claude Code BEFORE sending anything and thus getting back an estimate of tokens thus SAVING YOU MONEY!
Side Note: Yes I can throw this up into the n8n Workflows ecosystem, to be honest I just don’t have the time at the moment so if someone from within the n8n team wants to or another community user, feel free to throw it up there, I tried going through the whole signing up for account etc. etc.
So if someone can throw it up there too, that would be awesome, otherwise just grab it from the Github then
Yeah so for now I just kept it really simple, the pricing was literally Pre-pulled data from websites based on what they list as the prices - So its super fast and sits in spreadsheets ready to go
It’s been setup with options to calibrate it in the future by doing direct calls to the v1/token endpoints however I kept clear of that as the goal was not to hit those points unless needed. Hence why I left it open for the community to take it over and start adding in additional ideas like getting the endpoints for more accurate estimates and then even scraping the web for even more.
For files it breaks things down into text ultimately so even with PDFs it gives that estimate.
The goal here: A ballpark idea of what it could be - so that if anyone is about to run something massive, they can have some form or human-in-the-loop opporunities. Especially with Agentic AI agents just going off and doing whatever and we just pay the bill and don’t even realize how many tokens sometimes agentic agents are using up lol.
Feel free to grab a copy and make it your own and adjust it around
The current version can be used both via form and via webhook - It’s pre-defined costs so that its super fast and doesnt require hitting any endpoints or anything as the first data was scraped from the web and put into spreadsheets.
You will need a Google Sheets OAUTH connection but then you’re good to go
Nice — pre-flight cost estimation is the right instinct. One thing worth baking into the estimate: tool/function definitions are re-sent on every call (~190 tokens each), so they’re a fixed per-call cost on top of the prompt + retrieved context, separate from the user’s input. If a web version is handy for quick what-ifs alongside your workflow, I built a free one (no signup) that takes traffic/model/retrieval/tools and returns monthly spend: AI agent cost calculator — estimate your monthly model spend · WisWes — ours, shows raw provider cost.
Useful workflow. @Wes_W makes a good point about tool definitions - the overhead is easy to undercount in agentic setups.
One addition worth considering: Anthropic has a dedicated token counting endpoint (POST /v1/messages/count_tokens) that accepts the same body as a real request and returns the exact token count before you commit to the call. Integrating that as a pre-flight HTTP Request node in n8n gives you accurate input token counts for Claude models, including tools and system prompts, without any approximation.