Free Tool

AI Token Optimizer & Prompt Compressor

TokenTrim shrinks prompts, JSON, code and logs before you send them to an AI model, and shows the tokens and money you save. It runs entirely in your browser.

Zero-network: 0 bytes of your text sent

Original tokens0
Compressed tokens0
Tokens saved0-0%
Cost saved per 1,000 runs$0.00

Token counts are estimates (typically within about 10–15% of a model’s own tokenizer); the saving is measured the same way on both sides. Prices are list prices checked November 2026: edit the price if yours differs.

Your input

Compression rules

  • Collapses extra spaces and blank lines. Code indentation is kept.

    Options
  • Lists of similar JSON objects become a table, so keys are not repeated on every row.

    Options
  • JavaScript, TypeScript, Python, Go, SQL, shell and YAML. Strings and URLs stay intact.

    Options
  • Repeated log lines become “[x42] message”. Long stack traces keep the first and last frames.

    Options
  • Compliance mode: emails, IP addresses, JWTs, AWS keys and API keys become [REDACTED].

    Options

Optimized output

Nothing to save yet

How to cut tokens in three steps

  1. Add your text. Paste it, or drop files, a folder or a .zip. Use “Load sample data” to see it work first.
  2. Choose the rules. Each rule shows how many tokens it saves, so you can keep the ones that help and turn off the ones that remove something you need.
  3. Copy the result. Paste the optimized text into your prompt, API call or chat. The cost estimate uses the model price you pick.

What each rule does

Every rule is deterministic: the same input always gives the same output, and nothing is rewritten by an AI.

RuleWhat it removesWhat it keeps
Whitespace & formattingExtra spaces, trailing spaces, runs of blank lines. Aggressive mode also minifies JSON and XML.Indentation (needed by Python and YAML) and anything inside quotes.
JSON to compact tableRepeated keys. A list of 100 similar objects names each field once instead of 100 times.Every value. Large numbers that JSON cannot hold exactly stop the conversion rather than risk changing a digit.
Strip comments & empty linesLine comments, block comments, Python docstrings and blank lines in JavaScript, TypeScript, Python, Go, SQL, shell and YAML.Strings, URLs, regular expressions, license banners and compiler directives such as //go:build.
Collapse logs & stack tracesRepeated log lines (grouped as “[x42] message” with a time range) and the middle of long stack traces.The first occurrence of every distinct message, the first frames and the last frame.
Redact secrets & personal dataEmails, IPv4 addresses, JWTs, AWS access keys, common API tokens, private keys and values of KEY=value secrets.Everything else. It is a best-effort filter, so read the result before sharing it.

Savings on the built-in examples

Measured with the tool’s own estimate and its default rules. Your results depend on how much of your text is formatting, comments or repetition.

ExampleBeforeAfterSaved
Bloated JSON API response2,49496161%
Verbose Kubernetes / Nginx logs3,37149085%
Comment-heavy Python code59224159%
Multi-file project (as packed from a folder)28517638%

Built to keep your data private

  • All processing happens in your browser tab. There is no server step, so there is nothing to upload or store.
  • Your text is never put into a web address or saved. Only your rule choices and price are remembered on your device.
  • Files you add are read as text only. Nothing in them is run, and file names are shown as plain text.
  • Archives are opened with limits, so a malicious zip cannot swell to gigabytes in your browser.
  • Secret files such as .env and private keys are skipped when you add a folder.

More free tools for teams and builders are on the free tools page.

FAQs

Frequently Asked Questions

TokenTrim is a free tool that shortens the text you send to an AI model. It removes whitespace, comments, repeated JSON keys and repeated log lines, can redact secrets, and shows how many tokens and how much money that saves. It is meant for developers and teams who pay per token.

It is free to use online. There is nothing to sign up for, no login and no limit on how many times you use it.

No. Pasted text, dropped files and zip archives are processed in your browser’s memory, and the page makes no request that contains them. You can check this in your browser’s developer tools: open the Network tab, paste something and watch that nothing is sent. The page records only anonymous usage events such as “copied”, never your text.

It is an estimate, usually within about 10 to 15 percent of a model’s own tokenizer. Every model counts slightly differently, and exact counts need each provider’s tokenizer. The estimate is applied the same way to the original and the trimmed text, so the percentage saved is a fair comparison even when the absolute numbers differ a little.

In most cases yes, because extra whitespace, repeated JSON keys and duplicate log lines carry little meaning. Two rules can remove information you may want: comment stripping removes explanations written in comments, and log collapsing keeps only the first copy of a repeated message. Turn those rules off for any part where that matters, and try the output on a copy before relying on it.

Tokens saved, divided by one million, times the price per million input tokens, times 1,000 runs. It counts input tokens only, at list prices checked in November 2026: Claude Sonnet 5.5 $2, GPT-4o $2.5, Gemini 3.1 Pro (prompts up to 200K) $2. Prices change, so edit the price field to match your plan. Output tokens, prompt caching and batch discounts are not included.

JavaScript and TypeScript (and C-style languages such as Java, C#, C, C++, Kotlin and Swift), Python, Go, SQL, CSS, and files that use # for comments such as shell scripts, YAML, Ruby and Dockerfiles. It reads strings before it removes anything, so a URL or a # inside quotes is left alone. If the text looks unbalanced, for example a string that never closes, it is left unchanged instead of guessed at.

Yes. Drop files, a folder or a .zip onto the input box, or use the buttons. Each file is added under a “--- path ---” header, and node_modules, .git, build folders, lockfiles, binary files, minified files and secret files such as .env and private keys are skipped. Limits keep your browser responsive: 500 files, 1 MB per file and 25 MB per zip.

It catches well-known formats: email addresses, IPv4 addresses, JSON Web Tokens, AWS access keys, common API token formats, private key blocks and values assigned to names like API_KEY, password or secret. It does not understand names, street addresses or free text, and it cannot know about a secret in a format it has never seen. Treat it as a safety net and review the output before you share it.

Made by Ovoform

Send form responses straight into your tools

Build a free Ovoform form with AI, then send every response to Slack, Google Sheets, Airtable or your own webhook. Start free.

Build a free form

Free to start. No credit card required.

Ready to Build Smart Forms with AI?

Ovoform is your gateway to effortless, intelligent, and high-performing funnel experiences to expand your global reach. Build smarter forms, automate form workflows, and gather powerful insights — all in minutes.

Get Started Free

No credit card required. Unlimited responses.