Course contents · Lesson 14 of 24

AI Cost and Latency Budgets for Customer Deployments

From Prototype to Production AI · Lesson 14 of 24 · 10 min Engineer

Week 9 at Nimbus Assure: item 13 on lesson 13's readiness checklist, budgets, is still missing. Meera asks what the assistant will cost each month; Nimbus IT, which runs it after you leave, asks how slow it may get. AI cost and latency budgets answer both. This lesson sets Nimbus's, cuts them and reports spend against them.

The household budget: two limits agreed in advance

A cost budget is the most the customer agrees to spend each month running the AI, split into line items. A latency budget is the longest a request may take, split into a slice per step and stated at a percentile such as p95, the time 95 in 100 requests stay within.

Agree both with Meera, the sponsor, and the Nimbus IT owner before the pilot, and add them to the scope beside lesson 9's success metrics. A big bill then becomes a number against a line, not an argument. And a budget is a limit, not a target.

Where AI costs come from: tokens, calls and infrastructure

Three things make the bill:

  • Tokens: the pieces of text a model reads and writes, about three quarters of an English word each (Tokens and Context Windows). Hosted models usually charge per million, with separate input and output prices.
  • Calls: requests to the model. Lesson 13's retries count, and so does every run of lesson 12's eval set.
  • Infrastructure: the servers, log storage and monitoring around the model (Cloud Cost Basics).

Measure tokens rather than guess them: every reply reports its tokens in and out, so average them over an eval run. If a model reasons before answering, that hidden reasoning is billed as output tokens too; Anthropic's SDK, for one, counts it in the billed output total.

Then multiply, with a worksheet written in Python. Its numbers and prices are illustrative, not a real provider's, so swap in your own. Save it as budget.py:

# budget.py: Nimbus model cost a month (illustrative)
claims_per_day = 160
days_per_month = 30
calls_per_claim = 1.1        # retries, invalid replies
tokens_in_per_call = 4_000
tokens_out_per_call = 300
price_in = 2.00              # $ per million tokens
price_out = 10.00

claims = claims_per_day * days_per_month
calls = claims * calls_per_claim
cost_in = calls * tokens_in_per_call * price_in / 1_000_000
cost_out = calls * tokens_out_per_call * price_out / 1_000_000
total = cost_in + cost_out
print(f"model calls a month: {calls:,.0f}")
print(f"input tokens:  ${cost_in:,.2f}")
print(f"output tokens: ${cost_out:,.2f}")
print(f"monthly total: ${total:,.2f}")

Run python3 budget.py in that folder. You should see:

model calls a month: 5,280
input tokens:  $42.24
output tokens: $15.84
monthly total: $58.08

A total a million times too big means a missing / 1_000_000; can't open file means you are in another folder. The flowchart traces the same sum, one input at a time.

Flowchart in six steps, each multiplied by one worksheet input shown on the right. 1, 160 emailed claims a day, the volume from discovery. 2, times 30 days: 4,800 claims a month. 3, times 1.1 calls per claim, for retries and invalid replies: 5,280 model calls. 4, times tokens per call, 4,000 in and 300 out: 21.12 million tokens in and 1.58 million out. 5, times the price per million, 2 dollars in and 10 dollars out: 42.24 dollars in plus 15.84 dollars out. 6, 58.08 dollars a month for the model calls of live claims. A dashed note says eval runs, hosting and logs are not in this sum yet. All numbers and prices are illustrative
Each step multiplies by one input, and input tokens make most of the bill.

The aha is step 5: input makes almost three quarters of the bill, though an input token costs a fifth as much as an output token, because each call reads 4,000 tokens and writes 300. At Nimbus, trimming what you send saves most.

Then add the rest. Fifteen runs a month of the 200-row eval set are 3,000 more calls, about $33, and at this volume servers and logs can cost more than the model. All of it is small next to 1,200 handler-hours of re-typing a month: the budget exists to catch multipliers, such as a retry loop.

Latency users will accept, step by step

Latency is the time from sending a request to receiving the whole answer (LLM Latency and Cost). What users accept depends on who waits. Jakob Nielsen's rule of thumb: about 0.1 s feels instant, 1 s keeps a person's train of thought, and 10 s is the limit of their attention. Chat assistants stream so people start reading at the first word.

Nobody watches a Nimbus draft being written: it starts when the email arrives, and lesson 13's target, 60 s at p95, almost always has it ready before a handler opens the claim. The review page, where a handler does wait, gets its own budget of about a second.

Build the budget from the total down: a slice per step, plus headroom, spare time no step owns. Retrieval here is fetching what the model reads, the email and its attachments; in a RAG app it also covers searching the documents.

Bar chart on a time axis from 0 to 70 seconds, illustrative. Row 1, the budget for a draft to be ready within 60 seconds at p95: retrieval 5 seconds, input checks 2, model call 20, output checks and saving 3, and 30 seconds of headroom for slow days and one quick retry, ending on a dashed 60-second line. Row 2, one claim whose first try times out: 7 seconds of retrieval and input checks, a first try that runs to its 30-second timeout, a 2-second wait, a 20-second retry and 3 seconds of output checks, ending at 62 seconds, past the 60-second line. Row 3, the review page, where a handler waits, has a budget of about 1 second, a sliver on the same axis
The model takes the biggest slice, and one slow first try can use up all the headroom.

The aha is the middle row. The model takes the biggest slice, so cuts pay most there. Headroom covers a quick retry, but a first try that hits lesson 13's 30-second timeout, followed by a full retry, ends near 62 s. A p95 budget absorbs that only while it hits fewer than 5 claims in 100.

Log each step's time in lesson 13's log line, or in a distributed trace, and check each against its slice. Check the total too: percentiles don't simply add, because the steps are rarely all slow on the same claim.

Cutting cost and latency: smaller models, caching, shorter prompts

When a line runs over, change the basket, not the meals: keep a cut only if lesson 12's eval set still passes.

  • A smaller model: cheaper per token and usually faster, but often weaker on edge and risky rows. Score it on the eval set first.
  • Shorter prompts: trim instructions and examples, and drop what the model doesn't need, such as email footers and repeated attachments. At Nimbus this saves the most.
  • Shorter replies: only the seven fields. A model writes one token at a time, so fewer tokens out means a faster answer.
  • Prompt caching: OpenAI and Anthropic can reuse the work on a prompt's repeated beginning, above a minimum length, and report those tokens separately (cached_tokens, cache_read_input_tokens). They are billed at a lower price and read faster, so put fixed instructions first and the claim last. Anthropic's cache expires after 5 minutes by default, so a quiet spell starts cold.
  • Response caching: reusing a whole answer for an identical request. It suits a bot asked the same questions, not Nimbus, where no two claims match.

Reporting spend to the customer

Spend nobody sees can't be held to a budget. Give the deployment its own API key in its own OpenAI project or Anthropic workspace, so this customer's usage stays apart from your other work. Add up the tokens in your own log lines too, and compare them with the invoice.

Each month, send Meera and the Nimbus IT owner the same one-page report, and set an alert at, say, 80% of the budget, so no overspend first appears on an invoice. With illustrative numbers:

Nimbus claims assistant: monthly report (illustrative figures)

Line                 Budget    Actual   Note
Model: live claims      $80    $60.72   5,520 calls, 1.15 per claim
Model: eval runs        $40    $36.30   3,300 calls, prompt change
Hosting and logs       $150   $148.00   flat
Total                  $270   $245.02   91% of budget

Cost per claim, all in          $0.051
Email to draft, p95     60 s      44 s

Explain every gap before anyone asks: live calls ran at 1.15 per claim against the worksheet's 1.1, so check the retry rate. Nimbus IT keeps sending this report after you leave, so it belongs in the handoff runbook, which comes later.

Check yourself

This month's live model spend is $60.72, against the worksheet's $58.08, with the same claims, tokens and prices. What changed?

Calls per claim: 1.15 instead of 1.1, so 5,520 calls instead of 5,280. With everything else fixed, only extra calls can raise the bill, so look at why tries fail.

A teammate suggests streaming the model's reply to get Nimbus drafts ready sooner. Will it help?

No. Streaming shows the first words sooner, not the last, and nobody is watching: the output checks need the whole JSON before the draft is ready.

A cheaper model halves the monthly model bill but fails more eval rows. Do you switch?

Not on price alone. The budget is a limit, not a target, and the eval set decides first; about $29 a month saved is small next to handler time spent fixing wrong fields.

Go deeper