laws-cache
Scan codebases for cacheable LLM API calls and generate caching layers with projected cost-reduction estimates. Paste code or point at a public GitHub repo — get a shareable report showing which calls are cacheable, how much you'll save, and copy-paste caching wrappers.
How It Works
- Detection — Regex patterns identify LLM API call sites (OpenAI, Anthropic, Google Gemini, OpenRouter) in JavaScript/TypeScript and Python code.
- Classification — Each call site is classified as
static(hardcoded prompt, 60% cache hit rate),template(prompt with variable slots, 35% hit rate), ordynamic(fully user-generated, not cacheable). - Cost Projection — Using real model pricing from OpenRouter, the system estimates current monthly spend and projected savings with caching.
- Code Generation — For cacheable call sites, generates a content-hash-keyed caching wrapper in the source language (JS or Python).
API Endpoints
| Method | Path | Purpose |
|--------|------|---------|
| GET | /laws-cache/health | Health check → {"ok":true} |
| POST | /laws-cache/api/scan | Submit code for analysis. Body: {source, sourceType: "paste"|"github", language: "js"|"py"|"auto", monthlyVolume?: number} |
| GET | /laws-cache/api/scan/:id | Get full scan results with call sites |
| GET | /laws-cache/api/report/:id | Get report data with OG meta for sharing |
| GET | /laws-cache/api/pricing | List cached model pricing from OpenRouter |
| GET | /laws-cache/api/stats | Aggregate stats: total scans, savings found, top patterns, recent scans |
Data Sources
| Source | URL | Refresh |
|--------|-----|---------|
| OpenRouter Models API | https://openrouter.ai/api/v1/models | Every 6 hours via node-cron + on startup |
| GitHub Raw Content | https://api.github.com/repos/:owner/:repo/git/trees/:branch?recursive=1 | On-demand per scan |
| GitHub File Content | https://raw.githubusercontent.com/:owner/:repo/:branch/:path | On-demand per scan |
All pricing data comes from the OpenRouter API. Scan results come from regex-based code analysis — no LLM calls are made for analysis.
Run Locally
npm install
PORT=4728 node server.js
# Open http://localhost:4728/laws-cache/
Stack
- Node.js >= 22, Express, better-sqlite3 (WAL mode)
- node-cron for pricing sync
- Vanilla JS SPA frontend (dark theme)
- No authentication required