Part 2 of 4 · 10 min read
Definitions
Covers: Definitions; The levers; Results; Design rules; Interview questions, with the follow-ups; Common mistakes; What the example does not do.
Definitions
Cost per resolved task
- Cost per resolved task: total spend divided by the number of tasks that actually succeeded.
Prompt cache, prefix cache
- Prompt cache (prefix cache): reuse of the processed form of an unchanged prompt prefix to save cost and time.
Exact cache, semantic cache
- Exact cache: stored answers returned for identical requests.
- Semantic cache: stored answers returned for similar requests, judged by embedding similarity.
Router, cascade
- Router: picks a model before calling it.
- Cascade: tries a cheap model first and escalates if a check fails.
Budget cap
- Budget cap: a hard limit on spend (or tokens or steps) for one task.
The levers
Results
| Policy (20,000 tasks, assumed) | Cost per task | Success | Per resolved | p50 / p95 latency |
|---|---|---|---|---|
| Large only | $0.0150 | 91.1% | $0.0165 | 10.8 / 10.8 s |
| Small only | $0.0013 | 64.4% | $0.0019 | 3.5 / 3.5 s |
| Router (85% accurate) | $0.0059 | 77.2% | $0.0076 | 3.5 / 10.8 s |
| Cascade | $0.0070 | 90.9% | $0.0077 | 3.5 / 14.3 s |
| Steps in a run | Without cache | With prefix cache |
|---|---|---|
| 5 | $0.083 | $0.039 |
| 10 | $0.230 | $0.078 |
| 20 | $0.716 | $0.177 |
| 40 | $2.451 | $0.450 |
| Semantic threshold | Useful hits | Wrong answers served |
|---|---|---|
| 0.95 | 16% | 1% |
| 0.90 | 50% | 4% |
| 0.85 | 84% | 16% |
| 0.80 | 98% | 38% |
| 0.75 | 100% | 66% |
- The cascade matched large-model quality at roughly half the cost, paying in tail latency.
- The router was cheap but lost quality because misrouted hard tasks fail with no second chance.
- A cap turned a $12 run into a $0.48 one.
- Caching helps most on long runs and stable prefixes.
Design rules
- Track cost per resolved task with traces (Level 9), split by step, model and tenant.
- Set a quality floor first, then minimise cost above it.
- Cap every run (dollars, steps, wall time) and define what happens at the cap.
- Cache the stable prefix: system prompt and tools first, volatile data last; measure hit rate.
- Use exact caches for deterministic lookups; treat semantic caches as risky and keep thresholds high, scoped per tenant and excluded for sensitive queries.
- Prefer cascades over blind routers where you can verify answers cheaply; evaluate the verifier.
- Compress context: summarise, truncate tool output, drop stale steps (Level 7).
- Batch non-urgent work and keep interactive traffic separate.
- Budget latency too: TTFT, time to first progress event (module 4), total.
- Re-evaluate routing when models or prices change; keep the policy in config, not code.
Interview questions, with the follow-ups
How do you keep cost per resolved task under control?
"Measure it per task from traces, cap each run, cache the stable prompt prefix, trim context and steps, then route: cheap model first with a verifier and escalation. In my simulation a cascade got about the same success as the large model, 91 percent, at roughly 47 percent of the cost, and a per-run cap turned a $12 runaway into $0.48." Follow-up: "What do you watch for?" The quality floor and the p95 latency, because escalation adds both cost and delay for hard tasks.
Router or cascade?
"A router decides before the call, so a misclassified hard task fails with no recovery: mine was cheap but only 77 percent successful. A cascade checks the cheap answer and escalates, so quality stays near the large model, at the price of extra latency on escalated tasks and the need for a good verifier." Follow-up: "What if verification is expensive?" Then the cascade's saving shrinks; use a router with a conservative threshold or sample-based verification.
When is prompt caching worth it?
"When a long prefix repeats: system prompts, tool definitions, documents, multi-turn history. For agents, which resend history each step, savings grow with run length; in my model the cost of a 40-step run dropped from $2.45 to $0.45." Follow-up: "How do you make it hit?" Keep the prefix byte-identical and put changing content at the end.
Would you use a semantic cache?
"Rarely for agents. I would use exact caches and prefix caches first." Follow-up: "Where would it be safe?" Public FAQ-style answers with a high threshold and a human-reviewed cache.
Common mistakes
- Optimising cost per call instead of per resolved task.
- Switching to a cheaper model with no quality floor or eval.
- No per-run cap, so one loop eats a day's budget.
- Volatile content early in the prompt, destroying cache hits.
- Semantic cache with a loose threshold, or shared across tenants.
- Router with no fallback, or a verifier nobody evaluated.
- Ignoring tail latency of escalations.
- Hard-coding prices and routes.
- Counting only output tokens; agents pay mostly for input.
What the example does not do
- All prices, success curves, distributions and rates are assumed; conclusions are directional, not measurements of any real model or provider.
- No real tokenisation, no real calls, no real caching behaviour (providers differ on cache lifetimes, minimum sizes and write prices).
- The verifier and classifier are random processes with fixed accuracy, not models with correlated errors.
- Task difficulty is a single number; real tasks differ in kind.
- Latency is a simple formula; no queuing, rate limits or network.
- The exact-cache figure depends entirely on the assumed repeat distribution.
- Optional real experiment (I did not run this): replay 500 logged tasks against two real models and a cheap verifier, and compute cost, success and p95 latency for large-only, small-only, a router and a cascade.
Check yourself
A cheap model costs one tenth as much per call. Why is cheaper per call not the right measure? (Cost per resolved task is. The small model cost $0.0013 per task but succeeded only 64.4 percent of the time, and a failed task still has to be handled.)
For the curious Routers and caches buy savings with errors
A classifier router cost $0.0059 per task but succeeded only 77.2 percent of the time, because hard tasks sent to the small model fail. A cascade (small model, cheap verifier, escalate) reached 90.9 percent at about 47 percent of the large-only cost, with a worse p95 latency (14.3 s against 10.8 s). A semantic cache at threshold 0.75 gave 100 percent hits and 66 percent wrong answers. Prices and curves are assumed.
What you will use daily at work
| Practice | What it looks like |
|---|---|
| Track cost per resolved task | Not per call or per token. |
| Cap each run in dollars | A cap must end the run in a defined state, not a crash. |
| Keep the prompt prefix stable | Put variable content last so the cache can hit. |
| Budget latency as well as cost | Time to first token and time per output token. |
Draft: confirm current provider prices, cache rules and rate limits; every number here is an assumed illustration.
What you must be able to say (one page)
- Measure cost per resolved task, not per call or per token. A cheap model that fails is expensive per success. In my simulation (20,000 tasks, assumed prices and difficulty curves) the large model cost $0.0150 per task at 91.1 percent success; the small model $0.0013 at 64.4 percent; per resolved task that is $0.0165 versus $0.0019, but a 64 percent success rate is a product failure, so the target is the cheapest policy above a quality floor. Every price and curve here is invented for the lab: use your own measurements.
- Agents cost more than their step count suggests. Each step re-sends the history, so input cost grows roughly with the square of the steps: for a large model with a 2,000-token system prompt and 850 tokens added per step, a 5-step run cost $0.083, 10 steps $0.23, 20 steps $0.72, 40 steps $2.45. Fewer steps and shorter context are the first savings.
- Prompt caching reuses an unchanged prefix (system prompt, tools, earlier turns). In my simulation (cached reads at a tenth of the input price, assumed) the same runs cost $0.04, $0.08, $0.18 and $0.45 at 5, 10, 20 and 40 steps: savings grow with run length. Keep the prefix stable (put variable content last) or the cache never hits.
- Exact and semantic caches. An exact cache returns a stored answer only for an identical request. A semantic cache matches similar queries through embeddings, and its value is more doubtful, because embeddings, vector search and similarity thresholds can all fail. My simulation shows the mechanism: with assumed similarity distributions, threshold 0.95 gave 16 percent useful hits and 1 percent wrong answers; 0.85 gave 84 percent and 16 percent; 0.75 gave 100 percent and 66 percent. A looser threshold buys hits with wrong answers. Do not semantic-cache anything user-specific, time-sensitive or high-stakes. The exact-cache hit rate in my run (92 percent) is an artefact of a heavily repeating assumed query stream; a real agent workload often repeats far less.
- Model routing. Use a powerful model for complex queries and a lightweight one for routine tasks; dynamic routing evaluates each request and picks a model by complexity or urgency. In my simulation a classifier router (85 percent accurate, threshold 0.45) cost $0.0059 per task but succeeded only 77.2 percent of the time, because hard tasks sent to the small model fail; its cost per resolved task fell from $0.0097 to $0.0068 as classifier accuracy rose from 0.6 to 0.95. A cascade (small model first, a cheap verifier, escalate to the large model on a failed check) cost $0.0070 per task at 90.9 percent success, about 47 percent of the large-only cost for the same success, with a worse p95 latency (14.3 s versus 10.8 s) because escalated tasks pay for both. The verifier quality (90 percent true-positive, 15 percent false-positive, assumed) drives the result; a verifier that wrongly passes bad answers silently lowers quality.
- Per-task budget caps bound the tail. With 2 percent of runs looping for 400 steps at $0.03, the uncapped mean was $0.49 per run and the worst run $12.00; a $0.50 cap cut the mean to $0.25, the worst run to $0.48, and stopped 105 of 5000 runs. A cap must end the run in a defined state (partial result, escalation), not just crash (Level 9 budgets).
- Latency is a separate budget. Time to first token (TTFT) and time per output token (TPOT) combine as total latency = TTFT + TPOT x output tokens. Escalation adds latency, caching lowers TTFT, streaming (module 4) lowers the perceived wait, and batch APIs suit non-urgent work, so separate online and batch traffic.
- Honest limits: simulated tasks, curves and prices; no real model calls; the router and verifier are statistical stand-ins.