Brevit Playground
Brevit semantically compresses data for LLM prompts to reduce tokens while keeping meaning and structure. Try brevity() (auto strategy) and optimize() (explicit) and compare formats.
Quick facts
Token reduction
Often 40–60% depending on structure
Auto mode
brevity() selects the best strategy
Works with
JSON, text, tabular arrays, more
Install
npm i brevit
Mode
Intent (optional)
Compare formats
Token counts are estimated.
JSON: 0
YAML: 0
Brevit: 0
JSON
—
YAML
—
Brevit
—
Test with OpenAI (via Puter)
Runs in your browser using Puter’s client-side API (no OpenAI key stored in this app). See Puter’s tutorial: Free, Unlimited OpenAI API.
Model
Prompt / Task
Tip: run Brevit first to compare AI response quality on the compressed input.
Original response
est. input tokens: 56
—
Brevit response
est. input tokens: 0
—
Installation & Features
Installation
Features & Functions
Core Methods
- brevity() — Auto mode that intelligently analyzes data and selects the best compression strategy automatically
- optimize() — Explicit optimization with optional ratio/intent parameters. Supports optimize(data, ratioOrIntent, intent)
- optimizeText() — Text compression with ratio control (0.0-1.0) for TextRank-based compression
Supported Data Types
- • JSON objects and arrays (with tabular optimization)
- • Plain text and structured text (TextRank compression)
- • PDF documents (text extraction)
- • Images (OCR text extraction)
- • Tabular data (arrays of objects)
- • Nested structures (flattened format)
- • Mixed content types
Key Features
- • JSON Optimization: Flatten nested structures, tabular arrays, abbreviation feature (10-25% additional reduction)
- • Text Optimization: Deterministic TextRank-based compression, lossless by default, ratio-based compression (0.0-1.0)
- • Image Optimization: OCR integration, metadata extraction, multi-provider support
- • Smart Detection: Automatically detects JSON strings, objects, text, and images
- • Hybrid Arrays: Automatically uses tabular format when possible, falls back to indexed format
Benefits & Performance
- • 40–60% token reduction on average (up to 70% for primitive arrays)
- • Preserves semantic meaning and structure
- • Works with all major LLM providers (OpenAI, Anthropic, etc.)
- • Reduces API costs and latency significantly
- • Improves context window utilization
- • Lightweight and memory efficient
- • Multi-language support (JavaScript, Python, C#)
Examples & Use Cases
JSON Optimization Examples
Input: {"friends": ["ana", "luis", "sam"]}
Output: friends[3]:ana,luis,sam
• Tabular arrays: Automatically formats uniform object arrays
• Nested objects: Flattens with dot notation
• Abbreviation: Creates aliases for repeated prefixes
• Nested objects: Flattens with dot notation
• Abbreviation: Creates aliases for repeated prefixes
Text Optimization Examples
• Auto Mode (Lossless): Keeps all sentences by default, uses TextRank for analysis
• Ratio Mode: Pass ratio (0.0-1.0) to keep top-ranked sentences
Example: optimize(text, 0.5) keeps 50% of sentences
Works on single sentences to large documents
Deterministic extractive pipeline (no LLM required)
Works on single sentences to large documents
Deterministic extractive pipeline (no LLM required)
Real-World Use Cases
- • E-Commerce: Optimize product catalogs, order data, customer info
- • Document Processing: Process legal documents, contracts, reports
- • Customer Support: Optimize tickets, chat logs, customer data
- • Financial Services: Process invoices, receipts via OCR
- • RAG Systems: Optimize retrieval data before LLM processing
- • API Integrations: Compress API responses for LLM analysis
Cost Savings Example
1M API calls/month:
Without Brevit: ~100 tokens × $0.002/1K = $200/month
With Brevit: ~50 tokens × $0.002/1K = $100/month
Savings: $1,200/year (50% reduction)
Brevit Format Overview
Key-Value Format: Uses key:value pairs separated by colons (no spaces for token efficiency)
Dot Notation: Nested objects use dots (user.contact.email)
Tabular Arrays: Uniform object arrays use compact format (items[3]{field1,field2}:)
Primitive Arrays: Comma-separated format (friends[3]:ana,luis,sam)
Hybrid Approach: Automatically detects optimal format, falls back to indexed format for mixed data
The format is LLM-friendly, easy to parse, and designed for maximum token efficiency while preserving semantic meaning.
When to Use Brevit
✅ Perfect For
- • LLM prompt optimization
- • Reducing API costs
- • Processing large datasets for AI
- • Document summarization workflows
- • OCR and image processing pipelines
- • RAG (Retrieval-Augmented Generation)
⚠️ Consider Alternatives
- • Human-readable JSON for APIs
- • Real-time REST API responses
- • Data under 100 tokens
- • Strict JSON schema validation needed
- • Complex nested structures where hierarchy is critical
