TokenTracker
Drop-in Python wrapper and CLI that logs LLM API calls to local SQLite and reports costs.
Tested on Linux
Use it
Linux x86_64
install toktally via uv tool
uv tool install toktally
Check that it works
tokentracker --help 2>&1The output should contain “dashboard”.
First thing to try
cat > /tmp/tt_stub.py <<'PY'
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
def do_POST(self):
n = int(self.headers.get('Content-Length', 0))
body = self.rfile.read(n) if n else b''
try:
data = json.loads(body or b'{}')
except Exception:
data = {}
model = data.get('model', 'gpt-4o-mini')
resp = {"id":"chatcmpl-test","object":"chat.completion","created":1700000000,"model":model,"choices":[{"index":0,"message":{"role":"assistant","content":"Hello!"},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":5,"total_tokens":15}}
out = json.dumps(resp).encode()
self.send_response(200)
self.send_header('Content-Type','application/json')
self.send_header('Content-Length',str(len(out)))
self.end_headers()
self.wfile.write(out)
def log_message(self, *a): pass
HTTPServer(('127.0.0.1',8765), H).serve_forever()
PY
cat > /tmp/tt_track.py <<'PY'
from tokentracker import OpenAI, summary, recent
client = OpenAI(api_key="test-key", base_url="http://127.0.0.1:8765/v1")
r = client.chat.completions.create(model="gpt-4o-mini", messages=[{"role":"user","content":"Hello!"}])
print("REPLY:", r.choices[0].message.content)
s = summary(days=30)
print(f"TRACKED calls={s['total_calls']} cost={s['total_cost_usd']}")
for c in recent(limit=1):
print(f"RECENT model={c['model']} tokens={c['total_tokens']} cost={c['cost_usd']}")
PY
echo stub-and-track-writtenpython3 /tmp/tt_stub.pyrm -f /tmp/tt_usage.db && TOKENTRACKER_DB=/tmp/tt_usage.db uv tool run --from toktally python /tmp/tt_track.py 2>&1Run tokentracker dashboard to see your logged LLM spending.
What it does
- Track LLM API costs automaticallyTested
How to use it
- In your Python code, import the client from TokenTracker instead of the OpenAI package:
from tokentracker import OpenAI. - Make API calls as usual; each call is logged to a local SQLite database.
- Use
summary(days=30)orrecent(limit=1)fromtokentrackerto read back calls and costs.
- In your Python code, import the client from TokenTracker instead of the OpenAI package:
- View spending in a command-line dashboardTested
How to use it
- Run
tokentracker dashboardto see API calls and costs.
- Run
- Set spending budgets and check themTested
How to use it
- Set a budget with
tokentracker budgets set monthly --limit <amount>. - Run
tokentracker budgets checkto see spend against each budget.
- Set a budget with
How far pickfit got
Linux x86_64
- Installs
- Starts
- 3 of 3 features work
- Works offline
Good for
- see LLM spending by model and day
- enforce spending budgets in CI
- project future spend from recent usage
- find spend spikes and cheaper-model savings
- compare cost of workload across other models
An alternative to AgentOps and LangSmith.
How pickfit tested it
Each run starts from a clean machine and follows the steps above. How pickfit verifies
Linux x86_64
Its main function works
- Replayed from scratch
- Works offline
- Checked on 30 Oct 2026
- Version 0.2.1
Differences the test machine hit
- README: pip install toktally
In the test: uv tool install toktally for isolated env - README: drop-in OpenAI client calling real API
In the test: used local stub OpenAI server at 127.0.0.1:8765 and TOKENTRACKER_DB=/tmp/tt_usage.db so no API key or network needed