Composite scenario, not a real company. Assembled from common industry patterns; every number is illustrative and its assumptions are listed at the end.
This case belongs to Models, routing and inference for AI Architects.
Context
- A public body must sort 2,000,000 text documents (letters, forms, reports) into 20 categories, so each reaches the right records team and retention schedule, within 30 days.
- The first design called the largest approved model once per document, as if each were a customer waiting.
Problem statement
At 1,900 input and 30 output tokens per document, real-time calls cost 40,400 cost units (cu) against a 6,000 cu budget. Speed was never the issue: 2,000,000 documents in 30 days is 0.77 a second.
| Goal | Target |
|---|---|
| Model cost | 6,000 cu or less |
| Time | Backlog done in 30 days |
| Human load | Fewer than 2% of documents sent to humans |
| Quality | Machine-accepted error rate: 95% interval upper bound at 5% or less |
Constraints
- Personal data goes only to the approved provider and region.
- Every decision must be traceable: document id, category, tier, confidence and prompt version.
- A person decides any document the machine is unsure about.
- Categories are fixed at 20; a new one needs a policy decision, not a prompt edit.
Why the traditional approach fell short
| Approach | Where it breaks |
|---|---|
| Rules on metadata | Work for form-coded documents, about 35% of the backlog; that part stays rules |
| Keyword rules | Break on free-text letters: the same topic in different words, boilerplate shared across categories |
| Classic ML classifier | Needs thousands of labelled examples per category, and retraining when categories change |
| Manual sorting | 3 minutes a document is 100,000 hours |
Options considered
| Option | Verdict | Reason |
|---|---|---|
| A. Rules for form-coded documents, people for the rest (non-AI) | Rejected as the whole plan | The remaining 1,300,000 documents at 3 minutes each are 65,000 hours |
| B. Real-time call to the large model per document | Rejected | 40,400 cu, nothing in the process needs an instant answer |
| C. Rules, then a batch cascade (small model, then large for uncertain documents), then a human queue, with weekly sampling | Accepted | Large tier only for hard documents, asynchronous pricing |
Solution architecture
Figure 1. Components of the batch classification pipeline
How to read this: documents flow left to right and get more expensive attention only when the cheaper stage is unsure.
Figure 2. One batch, with expiry and the human path
How to read this: the loop at the top is waiting, the second loop sorts each result into one of three paths, and the document id ties every step together.
How AI solved it, step by step
Step through the pipeline, then try "Without the fix".
Under the hood
Two things are called batching. The API batch used here is a queue processed asynchronously. As of 2026-10-22, the Anthropic and OpenAI batch documentation both state a 50% discount against synchronous calls, a 24-hour maximum window, results in any order (match by custom id) and per-batch limits that differ (the plan uses the smaller 50,000). Neither explains how the discount is produced, so do not assume.
Inside a model server, batching is a different mechanism (Under the hood: Continuous batching and paged KV memory). The Orca paper schedules per model iteration, not per request, so finished requests leave and new ones join. The PagedAttention paper observes that key-value cache memory limits how many requests fit, and that earlier systems stored only 20.4% to 38.2% of it as real token state.
| The paper's 13-billion-parameter model | Value |
|---|---|
| Cache per token | 800 KB |
| One 1,900-token document | 1,556,480,000 bytes, about 1.56 GB |
| Cache space on a 40 GB card (about 30%) | about 12 GB |
| Whole documents at once | 7 (7.7 by division) |
This is the paper's model, not the provider's, but it shows why server batching matters at 2 million documents.
A small call costs 0.1 of a large one, and 30% of the 1,300,000 model-path documents escalate. Set escalation to 0.5.
At 0.3 the cascade costs 0.00808 cu a document: 10,504 cu for 1,300,000, or 5,252 cu at batch prices. At 0.5 it is 0.01212 cu, 7,878 cu at batch prices, over budget.
What went wrong / failure modes
| Failure | What happens | Mitigation |
|---|---|---|
| Miscalibrated confidence | The small tier reports 0.95 on wrong answers | Weekly Wilson-interval gate, per category, and a threshold that moves |
| Expired or failed requests | Unfinished requests expire at the window's end | Resubmit once by document id; writes are keyed by id and prompt version, so a retry cannot duplicate |
| Results matched by position | Output order may differ from input | Join on custom id only |
| Uncertain share grows | At 50% uncertain instead of 30%, cost is 7,878 cu, over budget | Alarm on the uncertain share; review label definitions first |
| Prompt edited mid-run | Two prompt versions in one backlog | Record the version on every decision and re-run a sample when it changes |
Results
These are illustrative targets, not measurements.
| Design | Model cost (cu) | Share of real-time cost | Documents to humans |
|---|---|---|---|
| Real-time, large tier for all | 40,400 | 100% | Not designed |
| Rules, cascade, synchronous prices | 10,504 | 26% | 31,200 (1.56%) |
| Rules, cascade, batch prices | 5,252 | 13% | 31,200 (1.56%) |
The batch cascade meets the 6,000 cu budget and the 2% human share; review is 1,560 hours (31,200 documents at 3 minutes).
| Weekly sample | Errors | Rate | 95% interval | Gate (upper bound 5% or less) |
|---|---|---|---|---|
| First | 12 of 400 | 3.0% | 1.72% to 5.17% | Fails: threshold raised |
| Later | 8 of 400 | 2.0% | 1.02% to 3.90% | Passes |
Tradeoffs and when NOT to use this approach
- Batch results arrive hours later: not for a person waiting.
- The cascade runs two passes on uncertain documents; it pays only when the small tier handles most.
- Where a wrong category has legal effect, sample more before auto-accepting.
- At small volumes the pipeline may cost more than it saves.
- Practitioners differ on fine-tuning a small model instead; that needs labelled data this body lacks.
Design rules extracted
- Ask whether anyone is waiting. If not, use asynchronous batch pricing.
- Send deterministic cases to rules before any model.
- Cascade by confidence, and calibrate the threshold against a human-labelled sample.
- Join batch results by id and make every write idempotent.
- Gate on an interval for the error rate, not on a single percentage.
Assumptions
Prices are invented cost units per million tokens: large 10 input and 40 output, small 1 and 4. Batch discount 50% (the documented figure, as of 2026-10-22, used as a ratio).
- 2,000,000 documents; 1,900 input tokens and 30 output tokens each. Large per document (1,900 x 10 + 30 x 40) / 1,000,000 = 0.0202 cu; small (1,900 x 1 + 30 x 4) / 1,000,000 = 0.00202 cu. Real-time large: 2,000,000 x 0.0202 = 40,400 cu. Rate: 2,000,000 / (30 x 86,400) = 0.77 per second.
- 35% rules: 700,000; model path 1,300,000. Small tier accepts 70%: 910,000; uncertain 390,000. Large tier leaves 8% for humans: 31,200 (1.56%), at 3 minutes = 1,560 hours. Manual: 2,000,000 x 3 / 60 = 100,000 hours; 1,300,000 x 3 / 60 = 65,000 hours.
- Batch cost: 1,300,000 x 0.00202 x 0.5 = 1,313; 390,000 x 0.0202 x 0.5 = 3,939; total 5,252; without discount 10,504. If 50% are uncertain: 650,000 x 0.0202 x 0.5 = 6,565 plus 1,313 = 7,878. Per document, cascade = 0.00202 + 0.3 x 0.0202 = 0.00808 cu; at 0.5, 0.01212.
- Batches: 1,300,000 / 50,000 = 26; 390,000 / 50,000 = 7.8, so 8.
- Wilson interval at z = 1.96 (the NIST e-Handbook's recommended interval for a proportion); error counts are invented.
- Cache: 2 x 5,120 x 40 x 2 bytes = 819,200 per token; x 1,900 = 1,556,480,000; 12,000,000,000 / 1,556,480,000 = 7.7.
- The agency and its documents are invented.
Last verified: 2026-10-22