Budget a document extraction pipeline before you run it
Extracting structured fields from thousands of invoices, contracts or records with an LLM can be cheap or eye-watering depending on document size, schema overhead and how often you retry. This estimator gives you a defensible per-document and total cost so you can size a pipeline — or compare models — before processing a single file.
How it works
Each document costs ((doc_tokens + schema_tokens) × input_price) + (output_tokens × output_price). The schema and instruction tokens are added to
every document because you resend them on each call, which is why short
documents with a big schema can cost more than you expect. The estimator then
applies your retry rate: an 8% retry rate inflates effective calls per
document to 1.08×, capturing the cost of re-running failed or low-confidence
extractions. Multiply by your document count and you have the total pipeline cost.
Worked example
For example, extracting 10 fields from 5,000 invoices using the following parameters:
- Average document length: 800 tokens
- Schema and instructions: 400 tokens (repeated every call)
- Expected output per document: 200 tokens (structured JSON)
- Retry rate: 10% (schema validation failures)
- Model: a mid-tier fast model at $0.15/M input, $0.60/M output
Per-document cost:
- Input: (800 + 400) / 1,000,000 × $0.15 = $0.000180
- Output: 200 / 1,000,000 × $0.60 = $0.000120
- Per-document subtotal: $0.000300
- With 10% retries: $0.000300 × 1.10 = $0.000330
Total for 5,000 documents: 5,000 × $0.000330 = $1.65
Compare the same pipeline on a premium model at $15/M input, $60/M output:
- Input: $0.018, Output: $0.012, subtotal: $0.030 × 1.10 = $0.033 per document
- Total: $165
The same extraction task costs 100× more on a frontier model. For well-defined field extraction from structured documents, a cheaper model with validation is almost always the right choice.
Schema overhead: the hidden cost multiplier
When extracting from short documents — receipts, form submissions, brief records — the schema and instruction text can exceed the document itself. A 200-token document paired with a 600-token schema is paying 3× as much for overhead as content. Short documents with large schemas are where cost-per-extraction can surprise teams who modelled cost purely on document size.
Strategies to reduce schema overhead:
- Remove field descriptions that the model can infer from the field name alone.
- Eliminate few-shot examples unless accuracy requires them — each example adds tokens on every call.
- Split a complex multi-field schema into two lighter calls if the document is short.
Tips to keep extraction cheap at scale
- Shrink the schema. Every redundant field description and example is billed on every document. Keep instructions tight.
- Use a cheaper model with validation. A mini/flash model plus a schema validator often beats a premium model on cost per correct extraction.
- Escalate, don’t blanket. Run everything on the cheap model and only retry the failures on a stronger one, rather than paying premium prices everywhere.
- Batch where you can. Batch APIs and longer prompts that pack multiple records can cut per-document overhead — just watch context limits and accuracy.