Wolfe-Jam/slash-tokens

Token Optimization for Context Engineers. 4.8 KB WASM. Sub-millisecond. Zero dependencies.

7

stars

151

commits

TypeScript

primary language

Aug 25, 2026

updated

slashtokens.com
ai
anthropic
bun
cloudflare-workers
context-engineering
cost-optimization
edge-computing
gemini
grok
llm
openai
tiktoken
token-counting
token-estimation
tokenization
tokenizer
tokens
vercel
wasm
zig
Browse cluster: LLM API gateways and cost management

README

/slash-tokens

npm version CI/CD npm downloads WASM size license ⭐ Star on GitHub

Token Optimization for Context Engineers. For anyone building with LLMs. 4.8 KB WASM. Sub-millisecond. Zero dependencies.

Know the cost before the call leaves your machine.

Models change. Windows grow. Slash adapts — you keep building. Cheaper tokens haven't shrunk the bill — usage has.

Current: slash-tokens@1.6.5 · release notes

Try it

bunx slash-tokens
# or: npx --yes slash-tokens

Run it in a project that already calls an LLM. An empty folder prints that nothing was found — that's normal.

See it work in a chat: live demo

Install

npm install slash-tokens
bun add slash-tokens

Auto mode

One import. Every LLM call checked pre-call.

import 'slash-tokens/auto'

Intercepts fetch() to Anthropic, OpenAI, xAI, and Google endpoints. Estimates tokens before the call leaves your machine. Sub-millisecond. Non-blocking.

[slash] Anthropic claude-sonnet-5 | 47,000 tokens | $0.0940 | OK
[slash] xAI grok-4.6 | 12,300 tokens | $0.0246 | OK

Pre-call check

preflight is analysis (every cheaper model, all providers). preflightRoute is the routing decision — same provider only. They answer different questions.

import { preflight, preflightRoute } from 'slash-tokens'

const prompt = 'Your prompt here...'

const check = preflight(prompt, 'claude-opus-5')
check.tokens       // estimated tokens
check.cost         // USD at the input rate
check.fits         // under this model's context window?
check.options      // cheaper models across providers — not a route

const route = preflightRoute(prompt, 'claude-opus-5')
// cheapest same-provider alternative, or null
// e.g. { model: 'claude-haiku', cost, salvaged, salvagePercent }

Fully typed. Do not use check.options[0] as the route — that list is cross-provider on purpose.

Token estimation

The engine underneath. 4.8 KB Zig-compiled WASM, calibrated against real provider tokenizers — not a flat chars/4 guess.

import { slash, slashBytes } from 'slash-tokens'

slash('Hello world')            // 2
slash(longDocument)             // 47283
slashBytes(new Uint8Array(buf)) // skip TextEncoder

Safe pre-check, not a perfect count. Pre-call, you only need go/no-go.

Models

Live ladder as of 2026-08-25. Generic aliases (claude-opus, gpt-5.4, grok-4.20, …) still resolve. Don't see yours? Open an issue.

Model$/M input$/M outputContext
claude-opus-55.0025.001M
claude-sonnet-52.0010.001M
claude-haiku-4.51.005.00200K
grok-4.62.006.00500K
grok-4.31.252.501M
gemini-3.1-pro2.0012.001M
gemini-3.5-flash-lite0.302.501M
gpt-5.6-sol4.0020.001.05M
gpt-5.6-terra2.0012.001.05M
gpt-5.6-luna0.201.201.05M
import { listModels, MODELS } from 'slash-tokens'

listModels()
MODELS['grok-4.6']  // { input: 2, output: 6, context: 500000, ... }

Savings reporting

Optional. bunx is the try path — no account.

import { init, report } from 'slash-tokens'

init({ key: 'mcp_slash_xxx' })

const result = await report({
  tokens_estimated: 47000,
  tokens_saved: 47000,
  model: 'claude-opus',
  action: 'skipped',        // 'skipped' | 'reduced' | 'routed'
  cost_saved_usd: 0.235
})

Hosted dashboard is ordinary SaaS: $39/mo or $390/yr for the data, not a cut of savings. One-person key: mcpaas.live/slash/setup

Runtime support

Node.js, Bun, Deno, Cloudflare Workers, Vercel Edge, Browser.

Testing

TypeScript SDK tests via cd npm && bun test. Zig coverage includes adversarial cases (CJK, emoji, binary, base64, thresholds).

License

Code: MIT. Fork it, ship it, change it, show it, share it, sell it.

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.


🏎️ Don't go to the Corner Shop in a Ferrari.

Contributors

Wolfe-Jam

151 commits

Wolfe-Jam/slash-tokens

Token Optimization for Context Engineers. 4.8 KB WASM. Sub-millisecond. Zero dependencies.

7

stars

151

commits

TypeScript

primary language

Aug 25, 2026

updated

slashtokens.com
ai
anthropic
bun
cloudflare-workers
context-engineering
cost-optimization
edge-computing
gemini
grok
llm
openai
tiktoken
token-counting
token-estimation
tokenization
tokenizer
tokens
vercel
wasm
zig
Browse cluster: LLM API gateways and cost management

README

/slash-tokens

npm version CI/CD npm downloads WASM size license ⭐ Star on GitHub

Token Optimization for Context Engineers. For anyone building with LLMs. 4.8 KB WASM. Sub-millisecond. Zero dependencies.

Know the cost before the call leaves your machine.

Models change. Windows grow. Slash adapts — you keep building. Cheaper tokens haven't shrunk the bill — usage has.

Current: slash-tokens@1.6.5 · release notes

Try it

bunx slash-tokens
# or: npx --yes slash-tokens

Run it in a project that already calls an LLM. An empty folder prints that nothing was found — that's normal.

See it work in a chat: live demo

Install

npm install slash-tokens
bun add slash-tokens

Auto mode

One import. Every LLM call checked pre-call.

import 'slash-tokens/auto'

Intercepts fetch() to Anthropic, OpenAI, xAI, and Google endpoints. Estimates tokens before the call leaves your machine. Sub-millisecond. Non-blocking.

[slash] Anthropic claude-sonnet-5 | 47,000 tokens | $0.0940 | OK
[slash] xAI grok-4.6 | 12,300 tokens | $0.0246 | OK

Pre-call check

preflight is analysis (every cheaper model, all providers). preflightRoute is the routing decision — same provider only. They answer different questions.

import { preflight, preflightRoute } from 'slash-tokens'

const prompt = 'Your prompt here...'

const check = preflight(prompt, 'claude-opus-5')
check.tokens       // estimated tokens
check.cost         // USD at the input rate
check.fits         // under this model's context window?
check.options      // cheaper models across providers — not a route

const route = preflightRoute(prompt, 'claude-opus-5')
// cheapest same-provider alternative, or null
// e.g. { model: 'claude-haiku', cost, salvaged, salvagePercent }

Fully typed. Do not use check.options[0] as the route — that list is cross-provider on purpose.

Token estimation

The engine underneath. 4.8 KB Zig-compiled WASM, calibrated against real provider tokenizers — not a flat chars/4 guess.

import { slash, slashBytes } from 'slash-tokens'

slash('Hello world')            // 2
slash(longDocument)             // 47283
slashBytes(new Uint8Array(buf)) // skip TextEncoder

Safe pre-check, not a perfect count. Pre-call, you only need go/no-go.

Models

Live ladder as of 2026-08-25. Generic aliases (claude-opus, gpt-5.4, grok-4.20, …) still resolve. Don't see yours? Open an issue.

Model$/M input$/M outputContext
claude-opus-55.0025.001M
claude-sonnet-52.0010.001M
claude-haiku-4.51.005.00200K
grok-4.62.006.00500K
grok-4.31.252.501M
gemini-3.1-pro2.0012.001M
gemini-3.5-flash-lite0.302.501M
gpt-5.6-sol4.0020.001.05M
gpt-5.6-terra2.0012.001.05M
gpt-5.6-luna0.201.201.05M
import { listModels, MODELS } from 'slash-tokens'

listModels()
MODELS['grok-4.6']  // { input: 2, output: 6, context: 500000, ... }

Savings reporting

Optional. bunx is the try path — no account.

import { init, report } from 'slash-tokens'

init({ key: 'mcp_slash_xxx' })

const result = await report({
  tokens_estimated: 47000,
  tokens_saved: 47000,
  model: 'claude-opus',
  action: 'skipped',        // 'skipped' | 'reduced' | 'routed'
  cost_saved_usd: 0.235
})

Hosted dashboard is ordinary SaaS: $39/mo or $390/yr for the data, not a cut of savings. One-person key: mcpaas.live/slash/setup

Runtime support

Node.js, Bun, Deno, Cloudflare Workers, Vercel Edge, Browser.

Testing

TypeScript SDK tests via cd npm && bun test. Zig coverage includes adversarial cases (CJK, emoji, binary, base64, thresholds).

License

Code: MIT. Fork it, ship it, change it, show it, share it, sell it.

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.


🏎️ Don't go to the Corner Shop in a Ferrari.

Contributors

Wolfe-Jam

151 commits

Languages

TypeScript

77.2%

HTML

22.4%