🎛️ Configure Your Usage
📊 Cost Comparison
| Model | Provider | Input Cost | Output Cost | Total Cost | Cost / 1K Req |
|---|
Don't let a while-loop bug burn your monthly budget in 30 minutes.
Provider spend limits usually work per organisation or project. LLM Token Guard is a free, single-file circuit breaker in Python & TypeScript that caps spend per run, user or agent session inside your own code, and stops an agent that keeps repeating the same steps.
🐍 Python package
token_guard.py with hard USD budget caps and loop detection.
🟦 TypeScript / Node.js package
tokenGuard.ts with the same caps and loop detection.
✅ Unit test suite
Tests included, so you can check the behavior before you rely on it.
📋 Quick start
Short Python and TypeScript examples, plus a list of free alternatives so you can pick what fits.
💡 Cost Optimization Tips
🔄 Use Prompt Caching
Most providers offer 50–95% off cached input tokens. If your system prompt is static, caching alone can cut costs by 30–60%.
📦 Batch Non-Urgent Requests
OpenAI, Claude, and Gemini all offer ~50% batch discounts. Great for analytics, embeddings, and overnight processing.
🪜 Route by Complexity
Use a cheap model (Haiku, Flash-Lite) for classification/routing, then send only complex queries to expensive models. Can save 70%+.
✂️ Trim Your Context
Every token in your prompt costs money. Summarize conversation history instead of passing the full thread. Use RAG to inject only relevant chunks.
Pricing sourced from official API documentation as of October 2026.
Calculations: cost = (tokens / 1,000,000) × price_per_million_tokens
Built with ❤️ — View on GitHub · Free & Open Source