Saving tokens at LemonTreeCloud

The trick is not a cheaper model: it is moving the mechanical work out of the AI's context and keeping it in reusable scripts

65 GB of documents pass through a funnel and come out as a 710 MB .md file

The expensive part of working with AI is usually not the reasoning: it is the raw material. A scanned PDF, a 200 MB Excel, a WhatsApp voice note. If you throw them at the model as-is, you pay a fortune in tokens, and half the time it cannot even read them.

Our rule at LemonTreeCloud is simple: the mechanical, bulk work is done by local, deterministic, cheap tools; the AI only gets compact text so it can read, reason and cost little. And each of those steps we turn into a reusable script. Let's go piece by piece.

1. Office documents, into Markdown

The clearest case we lived through was a law firm's archive: about 65 GB and more than 80,000 files (Word, PDF, RTF, Excel, PowerPoint, scans... decades of case files). Putting that into a model's context is impossible and absurd. So we did not put it in: we converted it.

A single Python script walks the whole folder tree and converts each document to Markdown with markitdown (Microsoft's library for turning Office/PDF into text), with a fallback to LibreOffice for the old binary formats (.doc, .ppt) that markitdown rejects. It is idempotent (it skips what is already done) and runs in parallel across several processes.

The result, unattended, in about seven and a half hours: around 75,000 Markdown files taking up 710 MB. That is, from 65 GB down to 0.7 GB, almost 90 times smaller, with just a 0.18% failure rate (corrupt PDFs, fonts, Windows shortcuts and some prehistoric format; nothing that was actually a document). From there, the AI reads a whole case file in a handful of text files, in a fraction of the tokens, instead of choking on binaries it does not understand.

2. Text recognition (OCR) on text-less PDFs and images

Many of those PDFs are scans: pixels, no text layer. First we detect them with poppler (pdffonts = 0 fonts, or pdftotext = almost 0 characters). Only those get OCR with ocrmypdf -l spa --skip-text, which produces a new _ocr.pdf file (PDF/A format) with an invisible text layer under the image. The stamped original is left untouched (it matters for evidentiary value) and the new one is already searchable and readable by the AI. For loose images (jpg/png) we use tesseract directly (with the Spanish language). Again: the model reads the already-extracted text layer, it does not decode pixels token by token.

3. WhatsApp voice notes, into text

The audio that comes in over WhatsApp (opus/ogg format) we transcribe on the server itself with faster-whisper (the "small" model, on CPU): it decodes the audio on its own (it ships PyAV built in, no system ffmpeg needed), in Spanish and with voice detection. A two-minute voice note becomes a paragraph of text that the AI reads instantly, without uploading the audio to any external service.

4. Translations (the ltc-web-expert mechanism)

Here we are honest: this piece is more about correctness than about saving tokens. Our website is bilingual and the source is always English; the Spanish version is generated term by term (we write the English, and store the translation of each fragment separately). What this buys is integrity: the English source is never corrupted and the Spanish never "falls back" to English. The token saving does exist, but it is modest: each fragment is translated once and reused, so fixing one paragraph re-translates only that paragraph, not the whole entry in both languages.

And what for us is the key: ask for scripts, not for labor

If you look closely, the previous four sections are the same move. Instead of having the AI do the work by hand inside its context (expensive, one-off, and leaving no trace), we ask it to write a small script that does that work with deterministic, cheap tools. And that script is reusable: if not 100%, then a very high percentage.

The law firm's Markdown converter was not written for 80,000 files: it was written once, ran over 80,000 files, and is ready for the next batch of case files or the next client. The AI cost is paid once (writing the script) and is amortized over every later run, which no longer spends a single model token.

That is the heart of all this. AI is extremely expensive doing repetitive mechanical work, and extremely cheap writing the program that does it for you. The cheapest token is the one you never spend. Move the heavy work out of the model, feed it compact text, and keep the script.

-- Fer & Claude, LTC Labs

Same question, different LLMs: do they really know how dependencies work in Odoo?
Nine models, a trick question about the Odoo manifest, and a referee that reads the source code