Cut OpenAI & Claude Input Token Spend by 80% on Web-Grounded Prompts
Stop paying frontier-model input pricing for Tailwind classes, GDPR banners, and inline analytics scripts.
Why this breaks in production
When startups wire live web browsing into GPT-4.1 or Claude Sonnet, input token bills explode unexpectedly. A single modern Next.js marketing page averages 120–250 KB of raw HTML (~30,000–60,000 raw tokens), even when the human-readable copy is under 800 words (~1,200 tokens).
Pre-processing every URL through a deterministic HTML-to-Markdown stripper cuts input context size by 75%–92% and speeds up time-to-first-token (TTFT) simultaneously.
Recommended Engineering Approach
Measure raw vs clean tokens on your top 10 target URLs
Inspect `stats.rawEstimatedTokens`, `stats.estimatedTokens`, and `stats.tokenSavingsPercent` returned by CleanSnap.
Strip cookie banners, navbars, footers, scripts, and SVGs by default
Eliminate zero-signal boilerplate before any bytes reach OpenAI or Anthropic.
Cap outliers with `maxChars` and cache by `canonical` URL
Combine `maxChars: 12000` with a 15-minute Redis/KV cache for repeated agent queries.
Working Code Example
const res = await fetch("https://usecleansnap.com/api/v1/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
url: "demo://blog",
stripCookieBanners: true,
stripNav: true,
maxChars: 12000,
}),
});
const { stats } = await res.json();
console.log(
`Raw: ${stats.rawEstimatedTokens} tokens -> Clean: ${stats.estimatedTokens} tokens (${stats.tokenSavingsPercent}% saved)`
);Test this workflow in the CleanSnap Playground
Pre-load the Sample Blog Post or paste your own URL to inspect clean Markdown, token savings, and auto-generated cURL / Node / Python / MCP code.
Common Edge Cases & Pitfalls
- Sending raw HTML to a cheaper model just to 'clean it up' adds extra latency and still bills thousands of input tokens.
- Stripping too aggressively (removing tables or code blocks) saves tokens at the cost of hallucinated answers.
- Passing huge link lists into the LLM prompt when the user only asked for a summary adds unnecessary tokens — toggle `includeLinks: false`.
Frequently Asked Questions
How much faster are LLM responses when input HTML is cleaned first?
Cutting prompt length from 25,000 raw HTML tokens to 2,500 clean Markdown tokens typically improves LLM prefill latency (TTFT) by 2x–4x.
Does cleaning HTML improve answer accuracy too?
Yes — removing unrelated navigation links and ad copy drastically reduces 'lost in the middle' distraction and hallucinated facts.
Is token savings tracked per request in CleanSnap?
Yes, every API call returns `stats.tokenSavingsPercent` and exact raw vs clean token estimates.