{"slug": "show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine", "title": "Show HN: Slash-tokens – know LLM cost before the call leaves your machine", "summary": "Slash-tokens 1.6.5, a 4.8 KB WASM library that estimates LLM token counts and costs before API calls leave the machine, is now available on npm. The tool intercepts fetch() calls to Anthropic, OpenAI, xAI, and Google endpoints, providing sub-millisecond preflight checks and routing decisions. It supports models like claude-opus-5 at $5.00/M input and gpt-5.6-luna at $0.20/M input, with an optional hosted dashboard at $39/mo.", "body_md": "Token Optimization for Context Engineers. For anyone building with LLMs. 4.8 KB WASM. Sub-millisecond. Zero dependencies.\n\nKnow the cost before the call leaves your machine.\n\nModels change. Windows grow. Slash adapts — you keep building. Cheaper tokens haven't shrunk the bill — usage has.\n\nCurrent: [slash-tokens@1.6.5](https://www.npmjs.com/package/slash-tokens) · [release notes](https://github.com/Wolfe-Jam/slash-tokens/releases/tag/v1.6.5)\n\n```\nbunx slash-tokens\n# or: npx --yes slash-tokens\n```\n\nRun it in a project that already calls an LLM. An empty folder prints that nothing was found — that's normal.\n\nSee it work in a chat: [live demo](https://slash-nextjs-wofejams-projects.vercel.app)\n\n```\nnpm install slash-tokens\nbun add slash-tokens\n```\n\nOne import. Every LLM call checked pre-call.\n\n```\nimport 'slash-tokens/auto'\n```\n\nIntercepts `fetch()`\n\nto Anthropic, OpenAI, xAI, and Google endpoints. Estimates tokens before the call leaves your machine. Sub-millisecond. Non-blocking.\n\n```\n[slash] Anthropic claude-sonnet-5 | 47,000 tokens | $0.0940 | OK\n[slash] xAI grok-4.6 | 12,300 tokens | $0.0246 | OK\n```\n\n`preflight`\n\nis analysis (every cheaper model, all providers). `preflightRoute`\n\nis the routing decision — same provider only. They answer different questions.\n\n``` js\nimport { preflight, preflightRoute } from 'slash-tokens'\n\nconst prompt = 'Your prompt here...'\n\nconst check = preflight(prompt, 'claude-opus-5')\ncheck.tokens       // estimated tokens\ncheck.cost         // USD at the input rate\ncheck.fits         // under this model's context window?\ncheck.options      // cheaper models across providers — not a route\n\nconst route = preflightRoute(prompt, 'claude-opus-5')\n// cheapest same-provider alternative, or null\n// e.g. { model: 'claude-haiku', cost, salvaged, salvagePercent }\n```\n\nFully typed. Do not use `check.options[0]`\n\nas the route — that list is cross-provider on purpose.\n\nThe engine underneath. 4.8 KB Zig-compiled WASM, calibrated against real provider tokenizers — not a flat chars/4 guess.\n\n``` js\nimport { slash, slashBytes } from 'slash-tokens'\n\nslash('Hello world')            // 2\nslash(longDocument)             // 47283\nslashBytes(new Uint8Array(buf)) // skip TextEncoder\n```\n\nSafe pre-check, not a perfect count. Pre-call, you only need go/no-go.\n\nLive ladder as of 2026-08-25. Generic aliases (`claude-opus`\n\n, `gpt-5.4`\n\n, `grok-4.20`\n\n, …) still resolve. Don't see yours? [Open an issue.](https://github.com/Wolfe-Jam/slash-tokens/issues)\n\n| Model | $/M input | $/M output | Context |\n|---|---|---|---|\n| claude-opus-5 | 5.00 | 25.00 | 1M |\n| claude-sonnet-5 | 2.00 | 10.00 | 1M |\n| claude-haiku-4.5 | 1.00 | 5.00 | 200K |\n| grok-4.6 | 2.00 | 6.00 | 500K |\n| grok-4.3 | 1.25 | 2.50 | 1M |\n| gemini-3.1-pro | 2.00 | 12.00 | 1M |\n| gemini-3.5-flash-lite | 0.30 | 2.50 | 1M |\n| gpt-5.6-sol | 4.00 | 20.00 | 1.05M |\n| gpt-5.6-terra | 2.00 | 12.00 | 1.05M |\n| gpt-5.6-luna | 0.20 | 1.20 | 1.05M |\n\n``` js\nimport { listModels, MODELS } from 'slash-tokens'\n\nlistModels()\nMODELS['grok-4.6']  // { input: 2, output: 6, context: 500000, ... }\n```\n\nOptional. `bunx`\n\nis the try path — no account.\n\n``` js\nimport { init, report } from 'slash-tokens'\n\ninit({ key: 'mcp_slash_xxx' })\n\nconst result = await report({\n  tokens_estimated: 47000,\n  tokens_saved: 47000,\n  model: 'claude-opus',\n  action: 'skipped',        // 'skipped' | 'reduced' | 'routed'\n  cost_saved_usd: 0.235\n})\n```\n\nHosted dashboard is ordinary SaaS: $39/mo or $390/yr for the data, not a cut of savings. One-person key: [mcpaas.live/slash/setup](https://mcpaas.live/slash/setup)\n\nNode.js, Bun, Deno, Cloudflare Workers, Vercel Edge, Browser.\n\nTypeScript SDK tests via `cd npm && bun test`\n\n. Zig coverage includes adversarial cases (CJK, emoji, binary, base64, thresholds).\n\n**Code: MIT.** Fork it, ship it, change it, show it, share it, sell it.\n\n**Brand: reserved.** The slash-tokens name, ⚡ mark, and red/gold colors stay with the project. If you're building on top of the SDK, ship under your own name and colors — don't represent your app as Slash. See [NOTICE](/Wolfe-Jam/slash-tokens/blob/main/NOTICE).\n\n🏎️ *Don't go to the Corner Shop in a Ferrari.*", "url": "https://wpnews.pro/news/show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine", "canonical_source": "https://github.com/Wolfe-Jam/slash-tokens", "published_at": "2026-08-25 22:48:31+00:00", "updated_at": "2026-08-25 23:14:28.152984+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-infrastructure"], "entities": ["slash-tokens", "Anthropic", "OpenAI", "xAI", "Google", "Wolfe-Jam"], "alternates": {"html": "https://wpnews.pro/news/show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine", "markdown": "https://wpnews.pro/news/show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine.md", "text": "https://wpnews.pro/news/show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine.txt", "jsonld": "https://wpnews.pro/news/show-hn-slash-tokens-know-llm-cost-before-the-call-leaves-your-machine.jsonld"}}