Skip to content

premmuditc/toastykey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

101 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—
  β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•
     β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘    β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•
     β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘     β•šβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β•β•    β•šβ–ˆβ–ˆβ•”β•
     β–ˆβ–ˆβ•‘   β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘      β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘
     β•šβ•β•    β•šβ•β•β•β•β•β• β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•β•   β•šβ•β•      β•šβ•β•   β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•β•   β•šβ•β•

Track. Control. Understand. The API cost layer for AI-native builders.

npm version License: MIT Tests PRs Welcome Node.js


The Problem

Your AI agents burn through API credits silently. You find out when the bill arrives β€” or when a runaway loop costs you $200 in an afternoon. ToastyKey sits between your code and every AI provider, logging every call, calculating every cent, and letting you set hard stops before the damage is done.


Quick Start

# Install globally
npm install -g toastykey

# Load demo data and launch
toastykey --demo
cp toastykey-demo.db toastykey.db
toastykey

# Open dashboard
open http://localhost:3000

Or try without installing:

npx toastykey

Dashboard Preview

Real-time API cost monitoring across all your AI providers β€” local, private, zero telemetry.

Overview Projects Anomaly Detection
Live spend, charts, provider breakdown Per-project cost attribution Rate spikes, cost spikes, error storms
localhost:3000 Auto-detected from API calls Auto-pause before you overspend

Try it yourself: npm install -g toastykey && toastykey --demo && cp toastykey-demo.db toastykey.db && toastykey


What You Get

Real-Time Cost Tracking

Stop guessing what your AI agents cost. Every API call to every provider is intercepted, logged, and priced in real-time. See your spend for today, this week, this month β€” broken down by provider, project, and model.

Beautiful Dark Dashboard

An Apple-aesthetic React dashboard that actually looks good. Spend trend charts, provider breakdown bars, "What You Got" tangible output counters (images generated, LLM calls, audio minutes, transcriptions). Monitor Claude Code costs, OpenAI spending, and all your other AI APIs in one place.

Budget Alerts That Actually Stop Things

Set a daily or monthly budget. When you hit 80%, get a warning. At 100%, ToastyKey auto-pauses the responsible provider or kills all API calls outright. No more discovering overspending after the fact.

Anomaly Detection

Six trigger types that watch for unusual patterns:

  • Rate Spike β€” sudden surge in calls per minute
  • Cost Spike β€” spending accelerating faster than normal
  • Error Storm β€” >50% of calls failing at once
  • Token Explosion β€” a single call using 10Γ— your average tokens
  • Silent Drain β€” API calls happening when nothing should be running
  • New Provider β€” your code suddenly calling a provider you've never used

Each trigger can log, notify, webhook, auto-pause, or auto-kill.

Encrypted Local Key Vault

Store all your API keys in one place, encrypted with AES-256-GCM. Auto-detect keys from .env files across your filesystem. Keys never leave your machine.

MCP Integration β€” Claude Code Sees Its Own Costs

"How much have I spent today?" β†’ β‚Ή2,847
"Set my daily budget to β‚Ή5,000" β†’ Done
"Which project is costing the most?" β†’ toastykey-dev: β‚Ή738

ToastyKey exposes 13 MCP tools directly to Claude Code. Your AI assistant can query its own API costs, set budgets, and get optimization recommendations β€” all without leaving the conversation.

Zero Config, Local-First

Everything stored in SQLite on your machine. No cloud account, no API key for ToastyKey itself, no telemetry, no data ever sent anywhere. Works offline.


Supported Providers

Provider Status Proxy Route Tracked Metrics
OpenAI βœ… Native /openai/* Tokens, cost, model, images, audio
Anthropic βœ… Native /anthropic/* Input/output tokens, cost, model
ElevenLabs βœ… Native /elevenlabs/* Characters, audio minutes, voice
Cartesia βœ… Native /cartesia/* Audio duration, model
Replicate βœ… Native /replicate/* Predictions, compute time
Stability AI βœ… Native /stability/* Images, steps, credits
Any REST API βœ… Generic /custom/:name/* Request count, latency

How It Works

Your Code
    β”‚
    β–Ό
ToastyKey Proxy (localhost:4000)
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  β”‚  1. Intercept request               β”‚
    β”‚  β”‚  2. Check budget (block if exceeded)β”‚
    β”‚  β”‚  3. Forward to real API             β”‚
    β”‚  β”‚  4. Parse response, calculate cost  β”‚
    β”‚  β”‚  5. Log to SQLite                   β”‚
    β”‚  β”‚  6. Check anomaly triggers          β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚
    β–Ό
Real API Provider (OpenAI, Anthropic, etc.)
    β”‚
    β–Ό
Your Code gets the response (unchanged)

Change one line in your code:

# Before (OpenAI example)
- OPENAI_BASE_URL=https://api.openai.com/v1

# After β€” all calls now tracked
+ OPENAI_BASE_URL=http://localhost:4000/openai/v1

That's it. No SDK changes, no code refactoring. The proxy is transparent.


MCP Integration (Claude Code)

Add to your Claude Code settings.json:

{
  "mcpServers": {
    "toastykey": {
      "command": "node",
      "args": ["/path/to/toastykey/src/index.js", "mcp"]
    }
  }
}

Or use the Settings page in the dashboard β€” it generates the config snippet automatically.

13 Available MCP Tools

Tool What It Does
get_spend_summary Today/week/month spend with provider breakdown
get_project_cost Cost for a specific project directory
get_session_cost Cost for the current Claude Code session
set_budget Create/update a budget (global, project, or session)
get_budget_status Check remaining budget and alert status
list_keys List all stored API keys (no values exposed)
add_key Store a new API key in the encrypted vault
get_anomaly_log Recent anomaly detection events
get_provider_stats Per-provider breakdown with costs and call counts
get_cost_breakdown Detailed cost breakdown by model and time period
pause_provider Pause all calls to a specific provider
resume_provider Resume a paused provider
get_recommendations AI-powered cost optimization suggestions

CLI Reference

toastykey                    # Start (with quick .env scan)
toastykey --no-scan          # Start immediately, skip scan
toastykey --demo             # Generate demo database
toastykey --port 5000        # Use custom port

toastykey scan               # Manually scan for new API keys
toastykey config             # Re-run setup wizard
toastykey watch list         # Show watched directories
toastykey watch add ~/code   # Watch directory for new projects
toastykey reset              # Reset all configuration

vs. Alternatives

Feature ToastyKey Helicone Portkey LiteLLM
Local-first βœ… ❌ Cloud ❌ Cloud βœ…
Free forever βœ… Freemium Freemium βœ…
MCP native βœ… ❌ ❌ ❌
Visual dashboard βœ… βœ… βœ… ❌ CLI
Anomaly detection βœ… ❌ ❌ ❌
Encrypted key vault βœ… ❌ ❌ ❌
Budget auto-pause βœ… ❌ Partial Partial
Any REST provider βœ… Generic Limited Limited βœ…
Zero telemetry βœ… ❌ ❌ βœ…

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ToastyKey                             β”‚
β”‚                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Proxy      β”‚    β”‚  Dashboard   β”‚    β”‚  MCP      β”‚ β”‚
β”‚  β”‚  :4000       β”‚    β”‚  :3000       β”‚    β”‚  Server   β”‚ β”‚
β”‚  β”‚              β”‚    β”‚  React + Viteβ”‚    β”‚           β”‚ β”‚
β”‚  β”‚  /openai     β”‚    β”‚              β”‚    β”‚  13 tools β”‚ β”‚
β”‚  β”‚  /anthropic  β”‚    β”‚  Overview    β”‚    β”‚           β”‚ β”‚
β”‚  β”‚  /elevenlabs β”‚    β”‚  Projects    β”‚    β”‚  Claude   β”‚ β”‚
β”‚  β”‚  /cartesia   β”‚    β”‚  Key Vault   β”‚    β”‚  Code     β”‚ β”‚
β”‚  β”‚  /replicate  β”‚    β”‚  Triggers    β”‚    β”‚  ↔        β”‚ β”‚
β”‚  β”‚  /stability  β”‚    β”‚  Reports     β”‚    β”‚  ToastyKeyβ”‚ β”‚
β”‚  β”‚  /custom     β”‚    β”‚  Settings    β”‚    β”‚           β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚         β”‚                   β”‚                           β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β”‚                   β–Ό                                     β”‚
β”‚           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                             β”‚
β”‚           β”‚   SQLite DB   β”‚                             β”‚
β”‚           β”‚  (local only) β”‚                             β”‚
β”‚           β”‚               β”‚                             β”‚
β”‚           β”‚  api_calls    β”‚                             β”‚
β”‚           β”‚  projects     β”‚                             β”‚
β”‚           β”‚  sessions     β”‚                             β”‚
β”‚           β”‚  budgets      β”‚                             β”‚
β”‚           β”‚  triggers     β”‚                             β”‚
β”‚           β”‚  api_keys     β”‚                             β”‚
β”‚           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack:

  • Backend: Node.js + Express, SQLite (better-sqlite3), Socket.io
  • Dashboard: React 18, Vite, Tailwind CSS, Recharts, Lucide
  • MCP: @modelcontextprotocol/sdk
  • Security: AES-256-GCM key encryption (Node.js crypto)
  • Pricing: Custom engine with model-level pricing for all providers

Installation Options

Global CLI (Recommended)

npm install -g toastykey
toastykey

From Source

git clone https://github.com/Knitefyre/toastykey.git
cd toastykey
npm install
npm run dashboard:install
npm run dashboard:build
npm start

Dev Mode (hot reload)

npm run dashboard:install
npm run dev   # Starts both proxy (4000) and Vite dashboard (3000)

Configuration

Config stored at ~/.toastykey/config.json. Override with:

TOASTYKEY_PORT=5000 toastykey          # env var
toastykey --port 5000                  # CLI flag
echo '{"port":5000}' > .toastykey.json # local file

Development

# Run all 148 tests
npm test

# Run tests with coverage
npm test -- --coverage

# Inspect the database
sqlite3 toastykey.db ".tables"
sqlite3 toastykey.db "SELECT * FROM api_calls LIMIT 5"

# Run just the MCP server (for Claude Code integration)
npm run mcp

Contributing

We welcome contributions! Please read CONTRIBUTING.md before submitting a PR.

Quick contribution guide:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/my-feature
  3. Make your changes + add tests
  4. Run npm test β€” all tests must pass
  5. Submit a PR against main

See CODE_OF_CONDUCT.md for community standards.


Security

API keys stored in the vault are encrypted with AES-256-GCM before being written to disk. The encryption key is derived from your machine's unique identifier and never stored in plaintext.

Found a security issue? Please report it privately β€” see SECURITY.md.


License

MIT License β€” premmuditc

See LICENSE for full text.


Dashboard Β· GitHub Β· npm Β· Issues

Built by premmuditc Β· Instagram

Track. Control. Understand.