Precision LLM Cost Forecasting Tool
Predict monthly operating costs within ±5% accuracy for chatbots and batch API operations across Claude and OpenAI models.
- Chatbot Calculator: Conversation-specific cost modeling with context accumulation
- Prompt Calculator: Batch API operations with optional multi-turn simulation
- 16 LLM Models: OpenAI (GPT-5 series, GPT-4.1 series, GPT-4o series) + Claude (4.5, 4.1, 4, and 3 series)
- Prompt Caching Support: Claude models with 90% cost savings on cached system prompts
- Cost Optimization: AI-generated recommendations for $500-$5,000/month savings
- Professional Reports: PDF and CSV export for both calculators
- Real-Time Calculations: <100ms updates as you adjust configuration
- CSV-Driven Pricing Updates: Quarterly pricing updates via automated utility (<100ms execution)
- Security-First: OWASP A03:2021 compliant, 0 vulnerabilities, privacy-by-design
- Accuracy: 0.00% - 3.90% variance (exceeds ±5% target)
- Test Coverage: 22/22 scenarios passing (100%)
- Bundle Size: 305 KB gzipped (40% under target)
- TypeScript: 0 errors with 11 strict flags
- Security: 0 vulnerabilities (npm audit clean)
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Update pricing data (quarterly maintenance)
npm run update-pricingVisit http://localhost:5173 to see the application.
- Frontend: React 18.3+ with TypeScript 5.6+
- Build Tool: Vite 6.4
- Styling: Tailwind CSS 3.4
- State: Zustand 4.5
- Charts: Recharts 2.12
- Exports: jsPDF 3.0 + jsPDF-AutoTable 5.0
src/
├── components/
│ ├── ChatbotCalculator.tsx # Chatbot cost calculator UI
│ ├── PromptCalculator.tsx # Prompt cost calculator UI
│ ├── ModelSelector.tsx # Model selection dropdown
│ ├── PromptInput.tsx # Multi-line prompt input
│ └── ... # Other UI components
├── config/
│ └── pricingData.ts # LLM pricing configuration (16 models, auto-generated)
├── store/
│ └── useCalculatorStore.ts # Zustand state (both calculators)
├── types/
│ └── index.ts # TypeScript type definitions
├── utils/
│ ├── costCalculator.ts # Core calculation engines
│ ├── optimizationEngine.ts # Recommendation generators
│ ├── validators.ts # Input validation framework
│ ├── csvExporter.ts # CSV export with security
│ └── pdfExporter.ts # PDF report generation
├── App.tsx # Main application with tab navigation
└── main.tsx # Application entry point
scripts/
├── types/
│ └── csvSchema.ts # CSV validation types
├── validators/
│ └── csvValidator.ts # Field and business validators (15 rules)
├── parsers/
│ └── csvParser.ts # CSV parsing with validation
├── transformers/
│ └── dataTransformer.ts # Data transformation utilities
├── utils/
│ └── pricingHelpers.ts # Code generation utilities
└── update-pricing-from-csv.ts # CSV-driven pricing updates (<100ms)
data/
└── pricing-update.csv # Quarterly pricing maintenance (11 columns)
firstTurnCost = (systemPrompt + userMsg) × inputPrice + response × outputPrice
// For Claude (with caching):
laterTurnsCost = (cachedSystemPrompt × cacheReadPrice + userMsg + context) × inputPrice
+ response × outputPrice
// For OpenAI (no caching):
laterTurnsCost = (systemPrompt + userMsg + context) × inputPrice
+ response × outputPrice
conversationCost = firstTurn + (laterTurns × (turns - 1))
monthlyCost = conversationCost × conversationsPerMonth- System Prompt Tokens: Size of your chatbot's system prompt (1-100,000 tokens)
- Avg User Message: Typical user input size (1-10,000 tokens)
- Avg Response: Typical AI response size (1-10,000 tokens)
- Conversation Turns: Number of back-and-forth exchanges (1-50)
- Conversations/Month: Monthly conversation volume (1-10,000,000)
- Context Strategy:
- Minimal: 50 tokens/turn (basic context)
- Moderate: 150 tokens/turn (recommended)
- Full: 300 tokens/turn (maximum context)
- Cache Hit Rate: For Claude models, % of conversations with cached system prompt (default: 90%)
TokenTally is a client-side only application with no backend, authentication, or database. Security focus:
- Dependency Security: Updated to patch CVEs (jsPDF 3.0.3, Vite 6.4.1, ESLint 9.39)
- Input Validation: All user inputs validated with min/max bounds
- CSV Formula Injection Prevention: Sanitizes
=,+,-,@characters - TypeScript Strict Mode: Type safety for financial calculations
- ESLint Security Plugin: Detects unsafe patterns
See SECURITY.md for complete security documentation.
TokenTally uses a CSV-driven pricing update system for quarterly maintenance:
- Edit CSV: Update
data/pricing-update.csvwith new model pricing (11 columns) - Run Utility: Execute
npm run update-pricingfor validation and code generation - Validation: 15 validation rules ensure data quality (11 field + 4 business rules)
- Auto-Generate: Creates
src/config/pricingData.tswith type-safe TypeScript code
Data Sources:
- OpenAI: https://openai.com/api/pricing/ (as of Jan 2025)
- Claude: https://www.anthropic.com/pricing (as of Jan 2025)
Pricing last updated: November 1, 2025 (16 models)
- Does NOT account for API retry costs
- Does NOT include rate limiting impacts
- Assumes consistent conversation patterns (no outliers)
- Context growth is linear estimate (actual may vary)
- Token estimates are approximate (~4 chars = 1 token)
# Run linter
npm run lint
# Run linter with auto-fix
npm run lint -- --fix
# Type checking only
npx tsc --noEmit
# Security audit
npm auditRun these 5 test scenarios to validate accuracy:
- Zero Conversations: 0 conversations/month → $0 cost
- Single-Turn: 1 turn → No caching benefit for Claude
- High-Volume Caching: 1000t system prompt, 10K conversations/month, Claude → Verify 90% cache savings
- Context Accumulation: Full vs Minimal strategy → Validate cost difference
- Model Comparison: Same config across all 16 models → Verify cheapest model identified
Hand-calculate at least 2 scenarios and compare to tool output (must be within 1%).
TokenTally is a static site ready for Vercel/Netlify:
npm run build # Creates dist/ folder
# Upload dist/ to hosting providerNo environment variables needed - fully client-side calculations.
MIT License - See LICENSE file for details
For issues, feature requests, or questions:
- Check
CLAUDE.mdfor architecture and development patterns - Review
SECURITY.mdfor security guidelines - See pricing data update process in
data/pricing-update.csvandscripts/update-pricing-from-csv.ts
Built with Claude Code - Precision cost forecasting for small business LLM chatbots