Token Budget Trimmer
Cut a document to an exact token budget by sentence or paragraph — kept text stays verbatim.
Document and budget
empty · 0 unitsEffective budget: 4,000 tokens · counting with tokenizer…
Trimmed output
0 of 4,000 tokens · 100% keptNo document yet
Load the demo document to see kept, shortened and dropped units.
Examples
Head + tail
Eight-paragraph document, 4,000-token budgetIntroduction + conclusion, marked middle cutThe gap marker is counted in the final token total so the exported text really fits.
Overhead reserve
8,000 budget, 300 overheadEffective budget 7,700The reserve updates live; an overhead at or above the budget disables fitting with an error chip.
Oversized unit
One sentence longer than the budgetShortened at a word boundaryA 60-percent word-boundary prefix plus a marker keeps a usable fragment instead of nothing.
Already fits
Short report, large budgetSource verbatim, 100% keptNo units are dropped or marked when the document already fits.
About this tool
The Token Budget Trimmer fits a pasted document into a numeric token budget by cutting whole sentences or paragraphs. It never summarizes or rewords: every kept unit is an exact slice of the source, and a visible marker shows where material was removed, so the final prompt keeps a clean audit trail.
Counts use GPT BPE encodings loaded locally in this tab — cl100k_base or o200k_base — with a characters-divided-by-four estimate for other model families. A budget, a reserve for system instructions, a unit mode and one of four strategies drive a deterministic solver; the assembled output is re-counted and a final overshoot is corrected automatically.
The diff pane labels each unit as kept, shortened or dropped with text and icons rather than color alone. Click a unit to pin a manual keep/drop decision, which locks automatic fitting until cleared. Documents are never uploaded or stored.
What this tool does not do
- Trimming means information loss: a dropped sentence is gone even though it stays visible in the diff.
- A single sentence too long for the budget is cut at a word boundary rather than rewritten.
- Counts are exact only for the bundled OpenAI encodings; other models tokenize differently.
How to use this tool
Paste a document
Paste or load a .txt/.md file. Load the demo document to see a multi-paragraph example immediately.
Set the budget
Enter a token budget or pick a preset, then reserve tokens for system instructions and other overhead.
Choose a strategy
Head preserves the opening, tail the conclusion, head + tail compresses the middle, and highest value prioritizes keyword-dense units.
Review and copy
Inspect the per-unit diff, override individual keep/drop decisions if needed, then copy or download the fitted text.
Use cases
RAG context stuffing
Fit ranked reference passages into the remaining context budget before sending a request.
Chat paste preparation
Trim a report excerpt to a model's limit without losing exact wording or citations.
Support macros
Fit a knowledge-base article into a response template while preserving original sentences verbatim.
Unit states in the diff
| Mark | State |
|---|---|
| ✓ | kept |
| … | shortened |
| ✗ | dropped |
Icons and text labels always accompany color, and a live region announces used tokens and percentage kept.
Common mistakes
Mistake:Assuming the estimate matches every model's tokenizer.
Fix:Pick cl100k_base or o200k_base for exact GPT counts; use the estimate only for families whose tokenizer is not bundled.
Mistake:Applying manual overrides and expecting auto-fit to continue.
Fix:Overrides intentionally lock the solver; clear them to return to automatic selection.
Mistake:Forgetting that markers consume tokens.
Fix:The solver reserves marker cost and re-counts the assembled output; watch the live total if you change the marker.
Frequently asked questions
Does it rewrite my text?
No. The trimmer only drops whole units or shortens one oversized unit at a word boundary. Every kept sentence or paragraph is a byte-identical slice of your source, and the diff shows exactly what was removed so you can verify the result.
How does the token count compare to my model's tokenizer?
cl100k_base and o200k_base are exact counts for the GPT models that use those encodings, computed locally with the same BPE tables. Other model families have different tokenizers; choose the characters-divided-by-four estimate for a rough number and leave headroom when you paste elsewhere.
What does the ellipsis mode keep?
Head + tail keeps the opening and closing units and inserts one marker where the middle was removed. The marker's own token cost is included in the final count, and if assembly pushes the output over budget, one more unit is dropped automatically.
How accurate is the budget fit?
The solver counts each unit with the chosen tokenizer, reserves marker cost, then re-encodes the assembled output and retries up to three times if it overshoots. BPE tokens can merge across boundaries, so always read the final live count before copying.
Can I override the automatic choices?
Yes. Click a unit's mark in the diff to toggle between keep and drop. Manual overrides disable auto-fit and show a banner; clear them to return to the selected strategy. The original document stays available through the source toggle.
Is my document uploaded?
No. Segmentation, token counting, fitting and export all happen in this tab. Tokenizer tables load once from this site's static assets; your text is never sent to a server and is not stored.
Related tools
Agent Tool Flowchart Builder
Design agentic tool-call DAGs with decision branches and bounded loops. Validates reachability, cycle handling, and emits clean Mermaid flowcharts — fully in your browser.
AI Agent Memory & Buffer Simulator
Compare sliding window, summary buffer, and vector memory strategies
AI API Client SDK Generator
Generate typed API client SDK files from OpenAPI specifications or cURL requests
AI Code Explainer
Explain code snippets with grounded cloud AI
AI Code Security Auditor
Scan source code for high-confidence OWASP Top 10 vulnerabilities
AI Code Translator
Translate code into idiomatic implementations in another language