🎛️ 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.
Cloud provider billing alerts arrive hours after an agent exhausts your budget. LLM Token Guard is a drop-in local circuit breaker in pure Python & TypeScript that enforces hard USD caps and halts recursive tool loops before tokens burn.
🐍 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.
📋 Copy-paste recipes
Integration examples for OpenAI, Anthropic Claude, and Google Gemini.
💡 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