The short version
- I had 500 messy files to clean up.
- Asking the AI to fix each one cost about 131,000 tokens.
- Asking it to write a program that fixes them cost about 5,500.
- The program got more of them right.
The job
Turn this:
{ timeout: "90s", endpoint: "api.internal:8080", enabled: "yes",
owner_note: "checkout breaks if this is down" } Into this:
{ timeoutMs: 90000, host: "api.internal", port: 8080, enabled: true,
priority: "urgent" } Most of it is simple rules. "90s" is 90,000 ms. "yes" is true. A program can do that.
One part is not a rule. Priority comes from a note a person wrote. "Checkout breaks if this is down" means urgent. That needs a model.
What I tried
1. The AI does every file
50 calls. 478 of 500 right. About 131,000 tokens.
2. The AI writes a program, and the program asks the AI about each note
501 calls. 473 right. 25 minutes. Not worth it.
3. The AI writes a program, and a small model reads all the notes at once
1 AI call. 489 right. About 5,500 tokens. Under a minute.
Here is the idea of the program it wrote, cut down:
const configs = tool("configs", {});
const notes = configs.map((c) => c.owner_note);
const priorities = tool("judge_priorities", { notes });
configs.map((c, i) => ({
timeoutMs: parseTimeout(c.timeout),
...parseEndpoint(c.endpoint),
enabled: parseEnabled(c.enabled),
priority: priorities[i],
}));The lesson
Writing a program alone did not save much. Number 2 proves that.
What worked was splitting the job:
- Rules go into code, written once.
- Judgment goes to a small, cheap model, all in one batch.
Then the big model's cost stays the same whether you have 500 items or 50,000.
Fine print
- Numbers 1 and 3 ran 3 times each, with the same result every time. Number 2 ran once.
- I made up the 500 files and the right answers myself.
- The writer model is glm-5.3-flash on Workers AI. The small model is Clef.
- The token counts leave out Clef, because its service doesn't report them.
- This job was mostly rules. If your job is mostly judgment, you'll save less.
- The program ran in amber, with no network access. It tried the program on 3 examples first. It passed every time.