DEV Community

Deployed Lab
Deployed Lab

Posted on Originally published at deployedlab.dev

The $11,000 model bill nobody could explain

The $11,000 model bill nobody could explain

Ledgerline is a made-up finance tool. Its invoice summariser works well, and its monthly model bill quietly grows to $11,000. Nobody can say which feature spends what. There is one bill and no meters. Most of the spend is a 40-page instruction document, sent fresh on every call. A nightly bulk job runs on the live, full-price tier because nobody moved it.

Nobody stole anything. Nobody made a dramatic mistake. The bill grew the way bills grow when nobody watches where the money goes.

Most of the bill is input

In most products, input tokens dominate the bill. Instructions, documents, and history are re-sent on every call, while the answer is usually short. You pay full price for the same words twice, a thousand times a day.

So measure cost per successful outcome, not per call. A cheap call that fails and retries three times costs more than one good call. And split the bill by feature. One total hides the feature that eats half the budget.

Think of a kitchen. Shared prep is your input; the plated dish is the output. Good kitchens prep once and serve many times. The same idea, applied to prompts, is where the largest saving usually sits.

Cache the stable prefix

Many providers offer prompt caching: if the start of your prompt matches a recent call exactly, the repeated part bills at a lower rate and processes faster. Check current pricing before you budget on the discount, because the terms move.

Three rules make it work. Put the stable parts first: system instructions, long reference documents, worked examples. Keep them byte-identical. One changed word or date near the front can break the match for everything after it. Put the variable parts last: the user's question, today's data, anything personal.

Design your prompt like a form letter. The letterhead never changes; only the name and the last paragraph do. That 40-page instruction document Ledgerline re-sent on every call is a letterhead. It should have been cached, not re-typed.

Cached input is cheaper, not free, and the discount varies by provider. Still, on a pipeline doing 100,000 calls a month, it is the first and biggest lever.

Cache answers, exact first, similar with care

An answer cache stores a finished reply and serves it again instead of calling the model. Exact-match caches are safe: same question, same user scope, same data version, same answer. "What are your opening hours", asked a thousand times, is a perfect candidate.

Semantic caches are riskier. They match questions that look similar, not identical, and the cache makes that judgement silently. Two failure modes follow. A similar question from another user gets the first user's personalised answer. Or a correct answer goes stale after the data changes.

Scope every key. Include the user or account, the data version, and the language. When the version changes, old answers die with it. A cache matched on similar wording that knew nothing about accounts is a privacy incident caused by a cost saving. Scope the key by user, or do not cache personalised answers at all.

Batch the work that can wait

Ask one question of every job: does a person need this answer in the next few seconds? If not, it is batch work.

Good batch candidates are nightly summaries, bulk extraction, backfills, and eval runs. Batch APIs from many providers price queued work lower, often around half price, in exchange for a turnaround window that can run up to a day. Check the provider's current terms.

Keep live what is live: chat, checkout help, anything a user is staring at. Batching those trades a saving for an angry user. Batching is not just a discount. It is a trade, and you pay with waiting time, so only patient work qualifies.

One bill, taken apart

A made-up pipeline summarises 100,000 reports a month. Every figure is illustrative. Each live call costs $0.11, of which $0.06 is the shared 6,000-token instruction prefix.

Step one, the baseline: 100,000 calls times $0.11 is $11,000 a month.

Step two, cache the prefix. Say cached input bills at one quarter of the normal rate. The prefix now costs $0.015 per call, so the new call cost is $0.065, and the monthly total is $6,500.

Step three, batch what can wait. Eighty percent of reports are overnight jobs, 80,000 calls at half price: $2,600. The other 20,000 stay live: $1,300.

Total: $3,900, down from $11,000. That is $7,100 saved, about 65 percent, with no change to the summaries themselves. Nobody swapped the model. Nobody cut quality. The same work simply stopped paying for the same words twice and stopped paying urgent prices for patient work.

Meters, or blank cheques

Tag every call with its feature, so spend lands in the right bucket as it happens. Set a budget per feature and alert at, say, 50, 80, and 100 percent of it. Track cost per successful outcome beside raw spend, so a "cheap" feature that fails often shows its true price.

A feature without a meter is a blank cheque: you learn its cost from the invoice, weeks later. Ledgerline's bill reached $11,000 before anyone looked because there was no meter to look at.

Skip caching when answers are personal and hard to scope safely, when source data changes faster than answers are reused, when volume is so low the cache costs more than it saves, and when one wrong repeated answer costs more than the calls ever would.

Before paying for a call, ask three questions: was it answered before, is the prefix cached, and can it wait? If any answer is yes, do not pay full price.

The full interactive chapter is free at https://deployedlab.dev/lessons/arch-12-caching-batching-cost, with a hands-on lab where you break a costly design and fix it. Deployed Lab has 79 chapters free with no signup, and the full bundle of 193 chapters is $5 a month or $39 a year at deployedlab.dev.

Top comments (1)

Collapse
 
sara_builds profile image
Sara •

The byte-identical prefix rule is the part I keep underestimating. We had a last-updated timestamp near the top of the system prompt, and every deploy quietly killed cache hits for a whole day. Moving that stamp to the end of the prompt was a one-line change and the hit rate came back. Tagging each call with a feature is the other piece I wish I'd done earlier — we shared one API key between the summarizer and a quick-rewrite helper, so the invoice couldn't tell us which path had jumped. Once we alerted at 80% of a per-feature cap, the helper was the one chewing tokens on retries after short answers. Do you keep dates and version notes out of the cached prefix, or is there a trick to include them without breaking the match?