Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLM Cost Engineering

Free · sign in to start and track progress

1 · Spending less on the same work

  • 1Token economics of an agent fleet
  • 2Prompt caching as system design

    Exercise answers

    • Answer: Simulate cache hits and costs for a matter
    • Answer: Measure warm-then-fan-out on your subscription
  • 3Trimming and compacting context
  • 4Batch, flex and fast tiers

2 · Changing the model, and governing the spend

  • 5Cost-quality curves, routing and cascades
  • 6Distilling into small models
  • 7Self-hosting break-even
  • 8Attribution, budgets and alerts
CapstoneCost-engineer an agent pipelineReference implementation

Module 1 · Spending less on the same work · Lesson 2

Prompt caching as system design

Turning a per-request cache into a fleet-wide strategy, with layered prefixes, cache-aware scheduling, the arithmetic of cache lifetimes, and hit rate as a monitored objective.

75 min 1 video 3 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvGet an OpenRouter key

By the end of this lesson you can

  • Derive the break-even number of reads for a cache write, and use it to choose between 5-minute and 1-hour lifetimes
  • Estimate hit probability from request arrival rates, and explain why per-case prefixes and shared prefixes need different strategies
  • Design a layered prompt layout and breakpoint plan for a fleet of agents
  • Schedule work so caches are warm when parallel or follow-up requests arrive
  • Monitor cache hit rate per agent and diagnose drops

On this page

  • Intuition: the reading room
  • The economics of one cache entry
  • Hit probability depends on the arrival process
  • Layering the prompt
  • Scheduling for the cache
  • The fleet-level result
  • Hit rate as an objective
  • Misconceptions and limits
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: the reading room
  2. 02The economics of one cache entry
  3. 03Layering the prompt
  4. 04Scheduling for the cache
  5. 05The fleet-level result
  6. 06Hit rate as an objective
  7. 07Misconceptions and limits
  8. 08Summary

Sources & further reading

  • Don't Break the Cache: An Evaluation of Prompt Caching for Long-Horizon Agentic TasksPaper · Lumer, Nizar, Jangiti, Frank, Gulati, Phadate, Subbiah · 2026The first systematic measurement of prompt caching on multi-turn agents across OpenAI, Anthropic and Google; 41–80% cost reductions, and evidence that controlling block placement beats naive full-context caching. Read the strategy comparison.
  • Prompt Cache: Modular Attention Reuse for Low-Latency InferencePaper · Gim, Chen, Lee, Sarda, Khandelwal, Zhong · 2023The research idea of precomputing and reusing attention states for recurring prompt segments such as system messages, templates and documents. Hosted APIs implement the simpler exact-prefix form; the paper shows what more flexible reuse would take.
  • SGLang: Efficient Execution of Structured Language Model ProgramsPaper · Zheng et al. · 2023RadixAttention shares cached prefixes across requests in a radix tree and schedules requests to maximise reuse. The self-hosted counterpart of the strategies in this lesson.
  • Auditing Prompt Caching in Language Model APIsPaper · Gu, Li, Kuditipudi, Liang, Hashimoto · 2025Shows that caches shared across users leak information through timing. The reason cache isolation per organisation or workspace is a security property, not just an accounting detail.
  • Prompt caching (Claude API docs)Docs · AnthropicBreakpoints, the 20-block lookback, minimum lengths, mixing TTLs and its billing positions, pre-warming with max_tokens 0, workspace isolation, and the note that a cache entry is only available once the first response starts.
  • Optimizing for cost and intelligence (Claude docs)Docs · AnthropicProduction numbers for agent loops (a median 84% of input read from cache) and the rule of thumb that below about 80% something is breaking the cache.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 8 more sections
  • 3 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks