Skip to content
echogeco
Cost, latency and routing · Cost and caching

A cache layout for the support bot

Reorder a support bot's request so its 12k shared prefix is served from cache, place the breakpoints, and cost the prefix per day before and after.

designmediumExercise · 4 min · 27 of 77
On this page

A support bot's owner turned prompt caching on a week ago and the bill went up. The request has everything the cache needs except the right order.

The situation

The bot answers customer chat for a subscription product. Each call carries 3k tokens of tool definitions, a 9k-token instruction block, and on average 8k tokens of conversation history, then the customer's latest message. The instruction block opens with a line the template fills in per call: Customer: Priya S · Plan: Pro · Now: 2026-10-16 09:41:07. Tools are rendered from a dictionary and arrive in whichever order the worker iterates them.

Volume is 20,000 calls a day. Caching was enabled with one breakpoint at the end of the instruction block; the dashboard shows cache_creation_input_tokens equal to the full 12k on every call and cache_read_input_tokens at zero.

Assume P_in = $3 per million input tokens, a cache write at C_w × P_in and a cache read at C_r × P_in, with C_w = 1.25 and C_r = 0.1, and a cache time-to-live of five minutes, refreshed on every hit. Ignore output tokens and the customer's own message; they are the same under every layout.

The question

Lay out the request so the 12k of shared content is served from cache, say where the breakpoints go, and give the daily cost of that 12k before and after — including what the current misconfiguration costs against caching turned off.

A strong answer · Rubric · Where answers go wrong

Write your answer first, then open