CertPrep
Domain 5 · Lesson 5.3 · 5 min read

Finding and Fixing the Cost Driver

Exam skillCost Diagnosis and Optimization

Analyzing usage or cost data to identify the dominant cost driver, selecting the optimization that addresses it, such as prompt caching (single, layered, and rolling breakpoints and checkpoint placement), batch processing, or token budgets, and quantifying the expected impact.

Break usage data down to find the dominant cost driver, then apply the optimization that targets it (single, layered or rolling cache breakpoints placed after stable content, batch processing for work that can wait, token budgets for long outputs, tool search for large tool sets) and estimate the saving.

What you need to know

Diagnose first

Split spend into input, output, cache write and cache read tokens, and into request volume versus tokens per request. Each driver has a different fix.

DriverOptimization
Repeated input prefix (system prompt, tools, documents)Prompt caching
Work nobody needs immediatelyMessage Batches API (about 50% off)
Long outputs nobody needsLength instructions and max_tokens budgets
Large tool sets on every requestTool search for rarely used tools
Simple requests on a large tierRoute to a smaller tier (see 5.2)

How caching works

  • A cache_control breakpoint caches the exact prefix up to it, in the order tools, system, messages.
  • Reads cost about 10% of normal input; writes cost 1.25x (five-minute lifetime) or 2x (one-hour lifetime).
  • Up to four breakpoints; prefixes below a minimum length are not cached.
  • Anything that changes before a breakpoint (timestamp, request ID, user name) makes every prefix unique. A change to tools invalidates everything cached after them.

Breakpoint patterns

PatternWhere breakpoints goFits
SingleAfter the stable system prompt and toolsOne shared prefix, varied questions
LayeredAfter the stable prefix, then after content that changes on a slower cadence (a customer's contract)Prefixes reused on different schedules
RollingOn the latest message each turnMulti-turn chats, so the growing history is reused

Batch and budgets

Batch suits nightly classification, re-scoring and bulk extraction: about half the price, results within 24 hours, matched by custom_id. For output-heavy features, a precise length instruction plus max_tokens cuts the largest line on the bill.

In the exam

Items show usage or cost data and a request layout, and ask for the dominant driver, the right optimization or the expected effect. Decompose the cost, then place breakpoints after stable content (layered or rolling where needed), batch what can wait, and budget long outputs. Distractors extend cache lifetimes for prefixes that never match, cache a changing timestamp, batch interactive traffic, or shrink the model regardless of quality.

Check your understanding

Question 1

92% of spend is input; every request repeats a 12,000-token system prompt and tools. Fix?

Show answer

Answer: C. Repeated input prefixes are exactly what caching targets.

Question 2

Cache reads are zero; the cached system prompt includes the current timestamp. Fix?

Show answer

Answer: B. Changing text before the breakpoint prevents every match.

Question 3

Multi-turn chats cache only the system prompt; input grows with each turn. Which pattern?

Show answer

Answer: D. Each turn then reuses the previously cached conversation.

Apply it: Cut Juniper's agent cost

Exercise · about 25 minCase: Juniper Outdoor Co.

Juniper's agent costs about $0.09 per conversation; input is 85% of spend. Each request sends 9,000 tokens of system prompt and tool definitions, then the conversation (average 6 turns), then a 2,000-token customer-order summary that changes per conversation. The review classifier runs realtime at 2 a.m.

  1. Identify the driver and design the breakpoints.
  2. Estimate the saving on the 9,000-token prefix for a 6-turn conversation, using the case's cache prices and Tier S (the agent's current tier).
  3. Fix the classifier's cost.
    Done when: every breakpoint sits after content that repeats exactly.
Check your work
Show model answer

1. Repeated input. Move the order summary to the start of the conversation (after the stable prefix) rather than resending it after every turn; breakpoint 1 after the system prompt and tools (shared by all conversations); breakpoint 2 after the order summary (shared by that conversation's turns); a rolling breakpoint on the latest message each turn.

2. Without caching, the prefix is sent six times: 54,000 tokens x $1 per million = $0.054 per conversation, more than half of the $0.09. With the prefix warm (it is shared by every conversation, so it stays cached), the same 54,000 tokens are reads at $0.10 per million = $0.0054. That saves about $0.049 per conversation, roughly 90% of the prefix cost, before the rolling cache on history.

3. Move the classifier to the Message Batches API, on Tier S if its evaluation passes: about half price from batch alone.

Key termsMessage Batches API

Sources