---
title: "#27: Prompt Caching"
description: "Prompt caching in the Claude API, which lets us reuse the start of a prompt across requests instead of paying full price to process it every time."
url: https://littlecupsofclaude.com/27
date: 2026-12-01
author: Jake Marsh
topics: ["API", "Context"]
---

# #27: Prompt Caching 💾

> Prompt caching in the Claude API, which lets us reuse the start of a prompt across requests instead of paying full price to process it every time.

Published 2026-12-01 by Jake Marsh on Little Cups of Claude. Canonical: https://littlecupsofclaude.com/27
Topics: [API](https://littlecupsofclaude.com/topics/api), [Context](https://littlecupsofclaude.com/topics/context)

Today we'll look at **prompt caching** in the **Claude API**, which lets us reuse the start of a prompt across requests instead of paying full price to process it every time.

When we send the same long system prompt, the same tool definitions, or the same document over and over, **Claude** can read that prefix from a cache. Cache reads cost a small fraction of normal input tokens, and long prompts get a faster first token too. Let's dive in.

## How The Cache Works

The cache covers a prefix of our request, always in this order: `tools`, then `system`, then `messages`. We mark where the reusable part ends, and the next request with an identical prefix reads it back.

By default an entry lives for 5 minutes, and every hit refreshes it at no extra cost. The clock starts when the request begins, so a response that takes 4 minutes to stream leaves us about a minute to send the follow-up.

## Automatic Caching

The simplest version is one top-level field. The API puts the breakpoint on the last cacheable block for us, and moves it forward as a conversation grows:

```typescript
const response = await client.messages.create({
  model: "claude-sonnet-5-5",
  max_tokens: 1024,
  cache_control: { type: "ephemeral" },
  system: "You are Hal, the Discovery One's onboard assistant.",
  messages,
});
```

Same thing in **Python**:

```python
response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    cache_control={"type": "ephemeral"},
    system="You are Hal, the Discovery One's onboard assistant.",
    messages=messages,
)
```

Each turn reads everything before the new messages from cache and writes only the new part. We never touch the markers again as the chat gets longer. Neat!

## Explicit Breakpoints

For finer control, we put `cache_control` on a specific content block. Here we cache a big ship manual that every request shares:

```python
response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    system=[
        {"type": "text", "text": "You are Hal. Answer from the manual."},
        {
            "type": "text",
            "text": ship_manual,  # thousands of tokens
            "cache_control": {"type": "ephemeral"},
        },
    ],
    messages=[{"role": "user", "content": "How do we open the pod bay doors?"}],
)
```

We can set up to 4 breakpoints in one request, which helps when sections change at different rates, like tools that rarely change and context that updates daily. Breakpoints themselves cost nothing. We only pay for what gets written and read. Automatic caching also uses one of those 4 slots if we mix the two.

## Reading The Usage Fields

The response's `usage` tells us exactly what happened:

```typescript
const { usage } = response;
console.log(usage.cache_creation_input_tokens); // written this time
console.log(usage.cache_read_input_tokens);     // read from cache
console.log(usage.input_tokens);                // after the last breakpoint
```

The gotcha here is `input_tokens`. It only counts tokens after our last breakpoint, not the whole prompt. The real total is all three added together. A request with 100,000 cached tokens and a 50 token question reports `input_tokens: 50`.

When streaming, the same fields arrive on the `message_start` event.

## The 1-Hour Cache

If our requests come less often than every 5 minutes, but more often than every hour, we can ask for a longer lifetime:

```python
{"type": "ephemeral", "ttl": "1h"}
```

Pricing works as multipliers on base input tokens: 5-minute writes cost 1.25x, 1-hour writes cost 2x, and cache reads cost 0.1x. On **Claude Opus 5.5** and **Claude Sonnet 5.5** reads are even cheaper, at 0.05x. When mixing lifetimes in one request, the 1-hour entries have to come before the 5-minute ones.

For a prompt we send more often than every 5 minutes, the default is the better deal, since each hit keeps refreshing it for free.

## Watch Out

Short prompts don't cache at all. The minimum is 512 tokens on current models like **Claude Opus 5.5**, **Claude Sonnet 5.5**, and **Claude Haiku 5.5**, and older models need 1,024 or more. Below that, the API skips caching without an error, so if both cache fields come back as 0, length is the first thing to check.

Changes also ripple forward through that `tools`, `system`, `messages` order. Editing a tool definition invalidates the whole cache, while changing `tool_choice` or adding an image only invalidates the messages part.

Finally, a new entry only becomes readable once the first response starts. For a burst of parallel requests, we wait for the first one to start responding before sending the rest.

More info about **prompt caching** can be found at [the Claude API docs](https://platform.claude.com/docs/en/build-with-claude/prompt-caching).
