Production LLM feature · LLM pipeline · cost & latency
Treating LLM output as a build artifact
Twelve interests give only 4,095 combinations, so I generated and fact-checked every answer ahead of time. Latency went from 31 seconds to instant, for about $121.
- request latency
- 31 s → instant
- request latency
- answers, all fact-checked
- 4,095
- answers, all fact-checked
- main run, ~3¢ per answer
- ~$121
- main run, ~3¢ per answer
- idea to production
- ~2 days
- idea to production
Try it
Every selection is a file that already exists
The made-up shop from the article: 12 filters, so 2¹² − 1 = 4,095 possible selections. Pick any filters and see which precomputed file the page fetches.
mask = 0
fetch pick a filter
- Before (V1)
- 31 s · 11 data + 7 model calls
- After
- one ~2 KB static file
- Model calls at request time
- 0
Problem
A visitor picks any of 12 interests and gets a paragraph describing people who share them.
In V1, each click made 11 data calls and 7 model calls. One request took 31 seconds.
Approach
I noticed that 12 items give only 4,095 combinations. So I pre-generated every answer as a ~2 KB static file on a CDN. There's no model, API key or rate limit in the request path.
On the frontend, every phrase is tagged to its source claim. Hovering a phrase shows the data behind it, so users can check the text.
Key decision
Split the writer and the checker
Using a frontier model for both writing and checking was projected at ~$490. To cut costs, I first tried a smaller writer. Only 25% of its claims survived the check, 52% after I capped claims at 20 words, and the paragraphs still weren't good enough to ship.
So I split the roles. Claude Opus writes through the batch API at half price, and Jev, a small decision model, fact-checks every claim against evidence data. The Jev checks for the 4,077 combinations in the main run cost 42 cents.
Results
- All 4,095 combinations shipped. The main run took ~53 minutes and cost ~$121, about 3 cents per combination and roughly a quarter of the original setup.
- Latency went from 31 seconds to instant.
- One-line idea to production in about two days.
What went wrong
The main run finished 4,077 combinations. Of the last 18, 10 went through on retries. The other 8 kept failing because Jev flagged correct claims as overstated: the criteria never said that naming two signals together was allowed.
I rewrote the criteria and raised the keep threshold from 0.5 to 0.6 for those 8. They finished for about $1.20 more.
What I'd do differently
I didn't measure how much of the saving came from batching and how much from moving the checks to Jev. Next time I'd split those out.
My test before the run was small: 3 claims, 2 paragraphs and 18 cross-checked claims. The run showed what it missed. Now I keep a set of known cases and rerun it after every change to the criteria.
When a run stalls on the same few inputs, I'd check the criteria before the writer, and sooner.
“If you can list every input, generate and check the answers ahead of time.”
Stack
- Claude Opus (Batch API)
- Jev
- Static files on CDN
- Next.js
- TypeScript