Reduce LLM API Costs by up to 70%

TokenWise

The smart toolkit to optimize JSON for Large Language Models.
Prune, compact, flatten, convert, estimate, and visualize tokens — all in one place.

Core Features

Powerful utilities designed to slash token usage and LLM costs

✂️
prune()
Remove unnecessary fields and reduce payload noise before sending to LLMs.
📦
compact()
Compress structure intelligently without losing semantic meaning.
📏
flatten()
Flatten deeply nested objects into clean, AI-readable structures.
📝
toNatural()
Convert structured JSON into natural language optimized for LLM input.
🔢
tokenEstimate()
Estimate token usage before sending requests to avoid cost surprises.
📊
visualizeTokens()
Interactive visualization of token distribution and usage (CLI + Web support planned).

Transform Examples

Real before/after transformations to see TokenWise in action

✂️

prune()

Before (Raw)
{ "user": { "name": "John", "age": 28 }, "debug": true, "internal": { "apiKey": "secret" } }
After (Pruned)
{ "user": { "name": "John", "age": 28 } }
📦

compact()

Before
{ "product": { "name": "Wireless Headphones", "price": 79.99 } }
After
{"product":{"name":"Wireless Headphones","price":79.99}}
📏

flatten()

Before (Nested)
{ "user": { "profile": { "theme": "dark" } } }
After (Flattened)
{ "user_profile_theme": "dark" }
📝

toNatural()

Before (JSON)
{ "name": "Alice", "theme": "dark" }
After (Natural)
User Alice prefers the dark theme.
🔢

tokenEstimate()

Input
The quick brown fox jumps over the lazy dog.
Estimated Tokens
≈ 9 tokens
📊

visualizeTokens()

Input Text
Token optimization helps reduce API costs significantly for large language models.
Visualization Output
Token Distribution: • Common words: 12 tokens (low cost) • Technical terms: 18 tokens (high impact) Total: 30 tokens | Suggested savings: 40%
🚀 Try Interactive Demo View on GitHub Sponsor Project

Frequently Asked Questions

What is TokenWise?

A lightweight toolkit that helps AI developers optimize JSON payloads to reduce token consumption and lower LLM API costs.

How does visualizeTokens() help?

It shows token distribution and highlights expensive parts of your input so you can optimize before sending requests.

Is TokenWise free?

Yes, the core library is open source and free to use. Sponsorships help keep development active.