Skip to content

budezllc/token-savers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Token Savers

Local AI gateway that sits between your IDE, agent, or app and your model provider. It shrinks prompts and completion budgets before tokens are billed — then forwards a normal OpenAI-compatible request upstream.

Works with Cursor, Cline, Continue, Open WebUI, custom scripts, or anything that speaks /v1/chat/completions. Upstream can be OpenRouter, OpenAI, Ollama, LM Studio, or any compatible API.

Usage dashboard showing tokens saved across Clip, Prune, Crush, RTK, Ponytail, and other savers

Version 0.1.1
License MIT
Default address http://127.0.0.1:20128
Platforms Windows desktop app · Node.js 20+ (macOS / Linux via server)

Install

Windows (recommended)

  1. Run the installer: Token Savers-Setup-0.1.1.exe (build one with npm run dist, or use a release build if you have it).
  2. Launch Token Savers from the Start Menu or desktop shortcut.
  3. The dashboard opens in the app window. Minimize or close (X) keeps it running in the system tray — use Quit in the tray menu to exit fully.

Uninstall from Windows Settings → Apps or the Start Menu uninstall entry.

From source (any OS)

npm install
npm run server

Open http://127.0.0.1:20128/.

Command What it does
npm run server Proxy + dashboard in the terminal
npm run dev Server + Electron window (Windows)
npm run app Build, then run Electron
npm run dist Windows NSIS installer → release\

If Electron fails to install: node scripts/fix-electron.mjs


First-time setup

  1. Open Upstream in the dashboard.
  2. Add a provider (name, base URL, API key, models). Examples:
    • OpenRouter → https://openrouter.ai/api/v1
    • OpenAI → https://api.openai.com/v1
    • LM Studio → http://127.0.0.1:1234/v1
    • Ollama → http://127.0.0.1:11434/v1
  3. Set the default provider and default model.
  4. Open Endpoint and copy:
    • Base URL: http://127.0.0.1:20128/v1
    • API key: the local ts-… key (this is not your OpenRouter/OpenAI key)

Point your IDE or agent at that local base URL and key. Upstream secrets stay only in Token Savers.


Features

Gateway

  • OpenAI-compatible GET /v1/models and POST /v1/chat/completions (streaming and non-streaming)
  • Multiple upstream providers with per-provider API keys and model lists
  • Local-only by default (127.0.0.1) — traffic stays on your machine
  • Live Log of client → post-saver upstream → response (in-memory; secrets redacted)
  • Usage estimates comparing tokens with vs without savers

Token savers

Every request runs through a local compression pipeline before it hits the provider. Toggle and tune each saver on the Token Savers page.

Prompt size (messages)

Saver What it does
Clip Drops old chat turns; keeps system messages and the last N user turns
Prune Shrinks chat and page-context scrapes: collapses repeated text, strips filler/stop words on large dumps, trims oversized context (including webpage text in the latest user message)
Blob Replaces data-URIs, long base64, and hex blobs in tool results with short markers
Dedup When the same tool payload appears again, keeps one copy and points later ones at it
Skeleton Large code dumps → keep imports/signatures; drop function bodies
Diff Unified diffs → keep headers and +/- lines; drop excess context
PathFold Repeated absolute path prefixes → ./
Whiteout Collapse blank lines, trim trailing spaces, minify pretty-printed JSON in tools
HtmlLite Strip scripts, styles, and HTML chrome from tool results; keep readable text
Crush Content-aware shrink of large JSON arrays, logs, and search dumps (keeps errors and relevant hits)
RTK Hard character ceiling on tool / tool_result content (head + tail)

Completion cost (reply length / request fields)

Saver What it does
Ponytail Injects brevity rules into the system prompt (lite / full / ultra)
ToolsTrim Drops unused entries from a large tools[] schema list
Cap Caps upstream max_tokens
Stop Adds stop sequences when the client omitted them (cuts verbose sign-offs)

Pipeline order:

Clip → Prune → Blob → Dedup → Skeleton → Diff → PathFold → Whiteout → HtmlLite
  → Crush → RTK → Ponytail → ToolsTrim → Cap → Stop → upstream

All savers are pure TypeScript in-process — no Python, no extra compressor installs.

Compression performance

Synthetic fixtures sized to trip each saver’s thresholds. Token estimates use chars÷4. Ponytail grows the prompt on purpose (brevity rules); Cap/Stop change request fields, not message size.

Re-run locally:

npm run test:report
Saver OK Before After Saved % What happened
Clip 55,858 7,227 48,631 87.1% 34 → 7 msgs; kept last 3 user turns
Prune 2,735 2,378 357 13.1% filler stripped on history turns
Blob 657 95 562 85.5% data-URI + base64 → [Blob: …] markers
Dedup 5,762 2,937 2,825 49.0% 2nd identical tool dump → pointer
Skeleton 5,437 219 5,218 96.0% large TS dump → imports/signatures
Diff 3,148 672 2,476 78.7% kept +/- lines; dropped context
PathFold 8,723 3,192 5,531 63.4% absolute prefix → ./
Whiteout 13,041 10,351 2,690 20.6% pretty JSON minified
HtmlLite 4,095 3,363 732 17.9% stripped script/style/chrome
Crush 27,041 3,489 23,552 87.1% 400-item JSON → errors/edges kept
RTK 12,000 4,000 8,000 66.7% hard tool-char ceiling
Ponytail 18 204 injected [Ponytail lite] (+186 chars)
ToolsTrim 6,958 2,515 4,443 63.9% tools 21 → 8
Cap max_tokens 8192 → 2048
Stop injected default stop sequences
Combined pipeline 104,658 13,727 90,931 86.9% full stack; Clip + Blob + Dedup markers present

All 16 checks passed. Estimated tokens saved on message savers (excluding Cap/Stop): ~48,987.


Dashboard

Page Use it for
Endpoint Local URL, API key, host/port
Upstream Providers, models, defaults, API keys
Token Savers Enable and tune each saver
Usage Estimated tokens saved over time
Log Live traffic: raw client request, compressed upstream payload, response

Connect your tools

Setting in your IDE / agent Value
Base URL / API base http://127.0.0.1:20128/v1
API key Local ts-… key from Endpoint
Model Any model id your upstream provider lists (or leave blank to use the dashboard default)

After a chat, open Log and compare the client request to the UPSTREAM entry — you should see smaller payloads and saver markers such as [Prune: …], [Clip: …], or [RTK compressed: …].


Config location

Settings persist on disk:

OS Folder
Windows %APPDATA%\Token Savers\
macOS ~/Library/Application Support/Token Savers/
Linux ~/.config/token-savers/

Override with env var TOKEN_SAVERS_CONFIG_DIR. Main files: config.json, usage.json.


Created by Kei Sakai — @KeiSakaiXkunani.dev

License

MIT — see LICENSE.

About

Token Savers — local OpenAI-compatible AI gateway with a token-saver pipeline

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages