Sub topic 11
Comparing cost, latency and maintenance
This chapter assumes you have read the earlier chapters on prompted extraction and on token-classification models with BIO tags. It also assumes you can read basic Python and know what a token is. Accuracy is only one input to the decision. A system that scores 2 points higher on F1 can still be the wrong choice if it costs ten times more, misses its response-time target, or breaks every time a vendor updates a model. This chapter gives you a way to put numbers on those three dimensions.
Where the costs come from
The two approaches pay in different places.
- Prompted extraction has almost no up-front cost. You write a prompt, run it on your gold set, and ship. You pay on every call, in proportion to the number of tokens processed.
- A fine-tuned token classifier has a large up-front cost: annotation, training, and evaluation. After that, each prediction is cheap. You pay mostly for the server that hosts the model.
This is the usual shape of the trade-off: variable cost against fixed cost. The question is at what volume the fixed cost pays for itself.
The numbers in the chart come from the illustrative prices in the next section. Real prices change often and differ by provider, so treat them as placeholders and substitute your own.
Modeling the cost of a prompted call
A prompted call is billed on input tokens and output tokens, usually at different rates. Output tokens are typically several times more expensive than input tokens. Input has three parts:
- The instructions and schema, which are the same on every call.
- The few-shot examples, which are also the same on every call.
- The document itself, which changes.
The first two are paid again on every request. A prompt with six few-shot examples can easily be larger than the document it processes. This is why adding examples improves accuracy but also raises cost on every single call.
Output size depends on your format. A JSON object with three short fields might be 40 to 80 tokens. A list of every entity span with quoted text and labels can be several hundred.
Two further effects change the real cost:
- Retries. If the output fails validation (see the chapter on structured output), you call again. A 5% retry rate means 5% more spend.
- Prompt caching and batch discounts. Some providers discount the repeated prefix of a prompt, and some discount asynchronous batch jobs. If your instructions and examples are a stable prefix, the effective input cost can drop a lot. Check your provider's current terms before relying on this.
A break-even calculator
The function below computes per-document cost for the prompted approach, the monthly fixed cost of the fine-tuned approach, and the volume at which they are equal. All prices are illustrative.
def prompted_cost_per_doc(prompt_tokens, doc_tokens, output_tokens,
in_price, out_price, retry_rate=0.0):
"""Prices are USD per million tokens."""
per_call = ((prompt_tokens + doc_tokens) * in_price
+ output_tokens * out_price) / 1_000_000
return per_call * (1 + retry_rate)
def finetuned_monthly_fixed(one_time_cost, amortize_months, hosting_per_month):
"""Spread one-time costs (annotation, training) over a planning horizon."""
return one_time_cost / amortize_months + hosting_per_month
def break_even_docs(monthly_fixed, prompted_per_doc, finetuned_per_doc=0.0):
saving = prompted_per_doc - finetuned_per_doc
if saving <= 0:
return None # the prompted approach is never more expensive
return monthly_fixed / saving
per_doc = prompted_cost_per_doc(
prompt_tokens=600, doc_tokens=400, output_tokens=60,
in_price=1.00, out_price=4.00, retry_rate=0.05,
)
fixed = finetuned_monthly_fixed(
one_time_cost=1500 + 50, # 1,500 docs labeled at about $1 each, plus training
amortize_months=12,
hosting_per_month=120,
)
print(f"prompted cost per document: ${per_doc:.5f}")
print(f"fine-tuned fixed cost per month: ${fixed:.2f}")
print(f"break-even: {break_even_docs(fixed, per_doc):,.0f} documents per month")With these inputs the break-even is a little under 200,000 documents per month. Below that volume, prompting is cheaper. Above it, the fine-tuned model is cheaper.
Change the inputs and watch how the answer moves. Halving the prompt size roughly halves the per-document cost and doubles the break-even volume. A cheaper hosting plan lowers it. If annotation is much more expensive, because the domain needs expert labelers, the break-even moves out a long way.
The model leaves out several real costs: engineering time, monitoring, human review of low-confidence outputs, and the cost of the errors themselves. Add them as extra terms if they matter for your project.
Latency
Latency is the time from sending a document to receiving a structured result. The two approaches differ in how that time is spent.
Generative models produce output one token at a time. Total latency is roughly the time to process the input, plus the number of output tokens multiplied by the time per token. This has two consequences:
- Long outputs are slow. A response of 300 tokens takes noticeably longer than one of 40.
- Latency varies a lot between calls. Queueing at the provider, rate limits, and retries create a long tail. The average can look fine while the slowest 1% of calls take many seconds.
Token classifiers do one forward pass over the input and read a label for each token. Time depends on input length and hardware, not on how many entities are found. A small BERT-class model on a CPU commonly responds in tens of milliseconds for a paragraph, and faster on a GPU. These are typical ranges, so measure on your own hardware. The result is also nearly constant from call to call, which makes capacity planning simple.
A few edge cases matter in practice:
- Input limits. Many encoder models accept at most 512 tokens. Longer documents must be split into overlapping windows, and entities cut at a window boundary must be merged. This adds code and some latency.
- Retries multiply latency. If a prompted call fails validation and you retry, the user waits for two calls.
- Throughput and latency differ. Batching improves throughput for both approaches but delays individual results. Decide whether you need answers interactively or overnight.
Measure latency by percentile, not just the mean. Report at least the median and the 95th or 99th percentile, taken from real traffic.
Maintenance
Maintenance is the cost that appears after launch, and it is easy to underestimate.
| Concern | Prompted LLM | Fine-tuned classifier |
|---|---|---|
| Schema change (new field) | Edit the prompt, rerun the gold set | Relabel data, retrain, re-evaluate |
| Upstream change | Provider updates or retires a model, and output may shift | You control the model file, so behavior is fixed until you change it |
| Data drift | New document formats may fail silently or degrade gracefully | Accuracy can drop on unseen formats until you add labeled examples |
| Fixing a specific error | Add an instruction or example, but this may disturb other cases | Add labeled examples of the error and retrain |
| Reproducibility | Hard if sampling is random or the model version changes | Easy with pinned weights |
| Tooling to keep | Prompt versions, validators, regression set | Training pipeline, data versions, model registry |
Two points deserve attention.
First, prompted systems are quick to change but fragile to change. Editing one sentence to fix one error can alter behavior on unrelated documents. The only protection is a regression run on the gold set after every edit. Pin the exact model version in your configuration, and schedule a re-evaluation whenever the provider announces a new version.
Second, fine-tuned models are slow to change but stable. A new field means new labels, which is real work. Once trained, though, the model behaves the same way tomorrow as today. That stability is valuable in regulated or audited settings.
Operational risks to plan for
- Rate limits and outages. A hosted LLM is a dependency you do not control. Plan for timeouts, backoff, and a fallback path, such as a queue or a simpler model.
- Data handling. Sending documents to an external API may conflict with privacy or contract rules. A self-hosted classifier keeps text inside your network. Self-hosting an open-weights LLM is a middle option, but then you pay for GPUs and operate them yourself.
- Cost surprises. Per-token billing scales with input size. One customer uploading very long documents can multiply your bill. Set input length limits and cost alerts.
- Silent failure. A prompted model can return plausible but wrong values with no error. Monitor field-level statistics, such as the share of nulls and the distribution of values, and sample outputs for human review.
- Hidden fixed costs of self-hosting. An idle GPU still costs money. A model that serves few requests may cost more per document than an API.
Reading the numbers together
Cost, latency and maintenance usually point the same way for a given project, but not always.
- Low volume, changing schema, unclear requirements: prompting wins on all three. There is little to amortize, and iteration is fast.
- High volume, stable schema, strict latency: a fine-tuned classifier wins. Per-document cost is low, latency is predictable, and the schema rarely changes, so retraining is rare.
- High volume but a changing schema: this is the hard case. A hybrid is often best, using an LLM to label data and a small model for serving. The next chapter covers it.
Exercise
A prompted extractor uses 800 prompt tokens and 200 document tokens per call, with 50 output tokens. Input costs $2.00 and output costs $6.00 per million tokens, with no retries. A fine-tuned alternative costs $300 per month fixed and almost nothing per document. What is the per-document prompted cost, and what monthly volume is the break-even point?
Show answer
Input cost is (800 + 200) × 2.00 / 1,000,000 = $0.002. Output cost is 50 × 6.00 / 1,000,000 = $0.0003. The total is $0.0023 per document. Break-even is 300 / 0.0023, which is about 130,435 documents per month. Below that volume the prompted extractor is cheaper, and above it the fine-tuned model is cheaper.
Exercise
Your service must answer within 200 ms at the 99th percentile. A prompted LLM has a median latency of 1.2 seconds. A teammate says that caching the instructions will fix this. Is that enough? What would you measure and consider instead?
Show answer
Caching the repeated prompt prefix can reduce input processing time and cost, but it does not remove the time spent generating output tokens one by one, and it does not remove network and queueing delay. A median of 1.2 seconds is already six times the 99th-percentile budget, so caching alone is very unlikely to be enough. Measure latency percentiles from real traffic and shorten the output format. If the budget is firm, consider a fine-tuned token classifier, which does a single forward pass and has stable latency.
Exercise
Name two maintenance tasks that are cheap for a prompted system but expensive for a fine-tuned classifier, and one that goes the other way.
Show answer
Cheap for prompting and expensive for fine-tuning: adding a new field to the schema (edit the prompt versus relabel and retrain), and trying a different label definition (rewrite an instruction versus relabel). The other way: keeping behavior identical over time. A pinned fine-tuned model never changes, while a hosted LLM can change when the provider updates or retires the model version.