Skip to content
Goal: Proficient✓ Sources verified 2026-11-24Prompt CachingBatchModel Routing

Cost, Latency and Prompt Caching ​

Once a B2B project is live, "cost per job" and "processing time" are the first two numbers customers and managers ask about.

Core concepts ​

TechniqueSavesWhen it fits
Tiered model routingCostSmall models for simple tasks (classification, extraction), large models for complex reasoning
Prompt cachingCost + time to first tokenEvery request carries the same long prefix (system prompt, documents, tool definitions)
Context trimmingCost + latencyInclude only relevant chunks (RAG) instead of the whole document
Batch APICost (async, not real-time)Overnight bulk processing that doesn't need an immediate response
Streaming outputPerceived latencyUser-facing generation tasks

How it works: prompt caching (Anthropic as the example) ​

  • The prefix is what gets cached: a request forms a prefix in the order tools → system → messages. Mark a content block with cache_control and everything before that point is cached. Later requests hit the cache only if their prefix is exactly the same.
  • Two ways to enable it: automatic caching with a top-level cache_control on the request, or manual breakpoints on specific content blocks.
  • TTL: 5 minutes by default (refreshed on each hit), 1 hour optional.
  • Price multipliers (relative to the base input price): 5-minute cache write 1.25×, 1-hour cache write 2×, cache read 0.1×.
  • Minimum length: below the model's minimum cacheable token count nothing is cached and no error is raised. Check cache_creation_input_tokens / cache_read_input_tokens in the response usage to confirm.

OpenAI also has prompt caching: it applies automatically to sufficiently long repeated prefixes with no manual marking (see the official docs for details).

Cost estimation formula ​

Cost per call = input tokens × input price + output tokens × output price
                (with caching: input splits into "regular input + cache writes + cache reads", each priced separately)
Cost per task = Σ the LLM call cost of every step in the task (so log task_id on every call)

In practice ​

python
# Put stable long content first with a cache marker, and changing content after it
resp = await client.messages.create(
    model=MODEL,
    max_tokens=1024,
    system=[
        {"type": "text", "text": AUDIT_RULES_LONG_TEXT, "cache_control": {"type": "ephemeral"}},
    ],
    messages=[{"role": "user", "content": f"Review the following contract fields: {fields_json}"}],
)
u = resp.usage
log.info("cache", write=u.cache_creation_input_tokens, read=u.cache_read_input_tokens, input=u.input_tokens)

Ordering rule when designing a prompt: what never changes (tool definitions, rules, examples) → what rarely changes (customer config) → what changes every time (the current document, the question).

Common pitfalls ​

  1. Timestamps or request IDs in the prefix: they differ every time, so the cache never hits.
  2. Thinking you're cached when you aren't: content below the minimum length is silently not cached. Always check the usage fields.
  3. Looking at unit price but not call count: one agent task may make a dozen calls. Cost only means something when measured per task.
  4. Routing to a small model with no evaluation safety net: compare accuracy on an eval set before switching to a smaller model.

Common interview questions ​

  1. How does prompt caching work? When does it stop working?
  2. How would you structure a prompt to maximize the cache hit rate?
  3. How do you measure and control the LLM cost of a task?
  4. What do you base tiered model routing on? How do you prove a smaller model isn't worse?

How it relates to my projects ​

  • AI Document Review Pipeline: the long review-rule text is a good fit for caching; the llm_call table records usage, so cost can be aggregated per task on the tracing dashboard.

To be verified / may go stale

  • The minimum cacheable length differs per model and can change, so this page gives no specific numbers. Use the table in the Anthropic docs.
  • The price multipliers (1.25× / 2× / 0.1×) were checked against the official docs on 2026-11-24; pricing rules may change.

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section