Back to issue
watch17 min

Prompt Caching Explained: Stop Overpaying for AI Agents

Hugging Face

The most immediately actionable seventeen minutes of the week. It explains the mechanic most agent builders get wrong: the LLM reprocesses your entire conversation on every turn, so costs compound quadratically — and a single timestamp in a dynamic system prompt invalidates your whole cache downstream. The worked example takes a 200K-token session from $41 to roughly $4 with correct caching.

  • A 50K-token session actually processes 50K + 51K + 54K... tokens cumulatively — cached tokens cost ~10% of full price across major providers
  • Dynamic system prompts (timestamps, changing working directories) invalidate the entire cache downstream — a silent, expensive bug
  • Cache expiry differs by provider: OpenAI 1 hour, Anthropic 5 minutes on the API but 1 hour in Claude Code
  • OpenAI and Hugging Face Inference cache automatically; Anthropic and Gemini require you to enable it explicitly
Watch on YouTube

Part of Issue Nº 004: OpenClaw's near-burnout, agent teams that ship 99.9% of PRs, and the math behind prompt caching