Show HN: Slash-tokens – know LLM cost before the call leaves your machine
slash-tokens is a lightweight (~4.8 KB WASM) TypeScript SDK that estimates LLM token counts and costs pre-call, intercepting fetch() to major providers (Anthropic, OpenAI, xAI, Google) It provides two key functions: `preflight()` for cross-provider cost analysis and `preflightRoute()` for same-provider cheaper alternatives, enabling go/no-go decisions before API calls leave the machine The token estimation engine is Zig-compiled WASM calibrated against real provider tokenizers, avoiding inaccura
Analysis
TL;DR
- slash-tokens is a lightweight (~4.8 KB WASM) TypeScript SDK that estimates LLM token counts and costs pre-call, intercepting fetch() to major providers (Anthropic, OpenAI, xAI, Google)
- It provides two key functions:
preflight()for cross-provider cost analysis andpreflightRoute()for same-provider cheaper alternatives, enabling go/no-go decisions before API calls leave the machine - The token estimation engine is Zig-compiled WASM calibrated against real provider tokenizers, avoiding inaccurate flat chars/4 heuristics, with sub-millisecond, non-blocking performance
- The project maintains a live pricing ladder (as of 2026-08-25) covering models like claude-opus-5 ($5/M input), grok-4.6 ($2/M), gemini-3.5-flash-lite ($0.30/M), and gpt-5.6-luna ($0.20/M)
- A hosted dashboard is available at $39/mo for tracking savings analytics, with MIT-licensed SDK supporting Node.js, Bun, Deno, Cloudflare Workers, Vercel Edge, and browsers
Why It Matters
As LLM context windows expand and usage scales, token costs compound despite per-token price declines—this tool addresses the growing need for cost visibility and optimization in production AI systems. For AI practitioners building agent workflows, RAG pipelines, or high-volume LLM integrations, pre-call token estimation prevents budget overruns and enables intelligent model routing decisions.
Technical Details
- Core Engine: 4.8 KB Zig-compiled WebAssembly module calibrated against real provider tokenizers (not heuristic approximations), supporting both string and byte-level token counting via
slash()andslashBytes() - API Design:
preflight(prompt, model)returns estimated tokens, cost, context fit, and cross-provider cheaper alternatives;preflightRoute(prompt, model)returns the cheapest same-provider fallback or null - Interception Mechanism: Hooks into
fetch()calls targeting Anthropic, OpenAI, xAI, and Google endpoints to estimate tokens before requests leave the client machine—sub-millisecond and non-blocking - Provider Coverage: Live pricing ladder includes Claude (opus-5, sonnet-5, haiku-4.5), Grok (4.6, 4.3), Gemini (3.1-pro, 3.5-flash-lite), and GPT (5.6-sol, 5.6-terra, 5.6-luna) models with context windows from 200K to 1.05M tokens
- Testing & Reliability: TypeScript SDK tests via Bun; Zig coverage includes adversarial cases (CJK characters, emoji, binary data, base64, edge thresholds)
Industry Insight
- The "cheaper tokens haven't shrunk the bill—usage has" insight reflects a broader industry trend: as model pricing drops, developers compensate by using more tokens, making cost-aware engineering practices essential rather than optional
- Pre-call token estimation and automatic routing to cheaper alternatives represents a practical pattern for production LLM systems—teams should integrate cost visibility into their CI/CD and monitoring pipelines, not treat it as an afterthought
- The $39/mo SaaS dashboard model (flat fee, no revenue share) suggests a sustainable monetization path for developer tooling in the AI infrastructure space, distinct from the percentage-based models common in AI cost optimization platforms
Disclaimer: The above content is generated by AI and is for reference only.