介紹 Toktail:開源 AI token 用量追蹤工具
Introducing Toktail
Toktail 是以 Apache 2.0 授權開源的 AI token 用量追蹤工具,可置於編碼 Agent 與 AI 服務之間記錄請求。它按模型、主機及每日統計 LM Studio 的輸入與輸出 token,支援最多 17 台主機,並可加密保存提示詞及回覆、備份至 S3 相容儲存桶。現時網站只提供 macOS Darwin arm64 安裝版本,適用於 Apple Silicon 電腦。
Today I want to tell you about an open source project called Toktail. It's free under the Apache 2.0 license. I used Claude Opus 5.5 and after 5.5 hours of render time on Max settings it created an AI token counter that sits between your coding agent and the AI you use. It tracks your usage in a local manner while keeping your prompt history secret. It has a built in chat agent that can interface with the proxied AI that provide you chat access to your Toktail data itself, including prompt history if tracked. It's small business friendly and designed to help the transition from only using public AI models to companies actually investing in local hardware for their top engineering talent to work unrestricted in a cost savings manner. This piece will explore the business use cases of Toktail and why I released this and what I hope to get out of it.
Open Source Apache 2.0 License
Toktail
Pronounced "tock-tail". A mix of token and tail -f.
Toktail counts every token your LM Studio hosts render, input and output per model, per host, per day. It watches up to 17 hosts at once, writes one CSV row per request, mirrors the files to an S3-compatible bucket, and shows the history in a local portal you can leave open all day. If you want, it also keeps the prompts and responses themselves (encrypted), so you can read search and re-run them, and it works out what your own hardware saves you against public API prices over its lifecycle. Pip the Token Fox lives in your menu bar and in the portal: napping when nothing is happening, munching while tokens stream, and losing its mind when your models all start talking at once.
Meet Pip
Pip sits between your apps and LM Studio. Every request that passes through…
Setting It Up
First, I want to be clear with you. I have not compiled Toktail for any other operating system, but nothing in Toktail's design prevents the Rust code from being compiled in any other language. Right now, the website only supports the macOS Darwin arm64 distribution to install on Apple Silicon computers. Once you have it downloaded, you can open it and it will live in your menu bar.
LMStudio is the local AI that I am using, however you can use any AI that you want. Toktail can be configured to point to OpenAI, Anthropic or any AI service that you choose. It'll let you bind the port to forward against and it'll begin letting you point your coding agents to ANTHROPIC_BASE_URL=http://localhost:1240 claude. Then, every request that Claude Code makes to Anthropic will be tracked through your instance of Toktail.
Now, every prompt that the coding agent sends over to Anthropic, you have a snapshot of the input and output tokens. Toktail cares deeply about the security of your privacy, which is why I instructed Claude to include advanced and high security standards to protect the data at maximum levels. This means that you can use per-prompt password generation using entropy strengthened passwords that can be managed in a local keystore, leveraged against the 1Password API by Agilebits, or connected to a Hashicorp Vault instance. Small business teams that use 1Password API for their team can now use Toktail to store the individual prompt passwords into a single vault - shared or unshared with write-only permissions granted to Toktail. For managers and administrators who can see everybody's prompt secrets, their API keys should allow read access.
I also tasked Claude Fable 5.1 the task of writing a merkle tree derived deduplication algorithm in rust that would build out the prompt tree from start to finish in the most deduplicated manner possible such that 1.93GB of encrypted and compressed prompt text can be reduced by 1.9 GB and remain at just 30MB on disk. When AI companies talk about the bubble, its really about that true footprint. Toktail captures that for you, but does it in a manner that is efficient on your disk and seemless in the interface to access.
I also asked Claude to include in Toktail the ability for S3 backups to generic backend sources with a time to live (TTL) on every object being uploaded. This functionality means that prompts can be moved off the host and onto the cloud whether that S3 is a local MinIO on your network or a public DigitalOcean bucket or an Azure bucket or an AWS S3 bucket or whatever S3 compatible API you choose to use. Your prompts stay in your S3 bucket and they live according to a lifecycle policy you define in these settings.
Collectively, with the ability to pass your Claude Code prompts from your agent directly into TokTail, then into Claude directly uninterrupted, your prompts are then locally captured, can be forked at positions and then handed off to a local model, and/or analysis can be performed against even S3 stored prompts.
When you're watching your tokens build up over time, you'll want to ask Pip the helpful mascot of the Toktail app information about your host usage, your cost analysis, and your prompt history directly with context and tools accessible to it, and other coding agents, via its internal MCP interface talking to the toktail API.
Using www.toktail.app I have pointed my coding agent through the tracking app and I have found that in the past week I have sent over 1B tokens and generated a few hundred thousand. This is common for coding agents. The ratio is found on the dashboard.
You can set up budgets for tokens that allow you to restrict, say a public paid model, on how many tokens per day its allow to render.
With the data that Toktail provides you, you can see your token usage over time and even watch major events that happen to Toktail over the course of your development efforts.
This is where Toktail really shines a major light on things for you. Check this out...
Yes, you're reading that correct. This is the price without the bubble at their current rates. At least, thats what I think here and what I conjecture. The cost isn't articulating the actual strategy used at these AI companies because they provide credits and caching services on prompts that reduce the bill rate of what is sent into the model versus what is billed to you. In my opinion, that difference, is the AI bubble and I believe that that difference has been subsidized in order to get companies hooked on Claude and hooked on GPT-6 knowing that it can one-shot "A Student" quality work, when in truth, the unskilled non-MCP connected public models are your "D Student" on-demand. Thinking that replacing your workforce of "A+ Students" with "D Student" AI systems is just silly, but for companies that are looking at the "A- Student" work that Fable 5.1 can do, the cost doesn't justify the exposure.
All companies need to do is put their host behind Toktail after reviewing the source code yourself if you don't believe me or Claude. The app doesn't phone home and it doesn't have telemetry. I don't have a clue how many people are using it and I don't really want to know. The mystery is what makes open source development so much fun. You serve everybody, even those who might curse me out.
Either way, Toktail is free and you can use it today. It runs on your local network for your own stuff and I've been using it now for a week. It's leveled up my local development efforts and I am planning on doing something about it.
I can keep posting online about it all I want getting 10 views here and 5 likes there or I can begin going around campuses in the United States and actually presenting the free open source solutions that I have to students so they can begin looking at the projects, running with them for their own means, or contributing back to the projects to fix areas that I may have skipped over. Either way, Toktail is free and open source and I want it to serve all who use AI in a way that gives you maximum transparency and sovereignty over your AI.
Getting Toktail set up on your system is easy and the benefits to it are enormous. If you appreciated my efforts, and you have the means to, please consider sponsoring my development on Github for $100/month and I'll add your company to a shout out section of my profile's README there. I'll even give you a shout out here too! Truly, if you find my work useful, sow where you want to reap and allow God to use me to multiply in you for you through me for me. That's why when we sponsor each other and we all win.
FYI the www.toktail.app website is being protected by concert a reverse proxy waiting room that is designed to sit between your Apache 2.4 web server and your port 443 serving HTTPS content. It protects your endpoint and allows you engage in x402 commerce on your websites. It's also free and opens ource like roc and www.toktail.app. Enjoy!
來源:DEV Community · dev.to












