Put the Claude cache breakpoint before changing request text on CometAPI

If a Claude request through CometAPI keeps reporting cache writes but no reads, check where the breakpoint sits before making the reference document longer. A repeated document is not enough if the only cache entry also includes a timestamp or a different question on every call.

This is specifically about independent questions over a shared reference, not an append-only conversation.

Why lookback may not rescue the reference

Anthropic’s prompt-caching guide distinguishes two operations: a write stores the cumulative prefix ending at a marked block; a read searches for a matching entry that an earlier request actually wrote.

Its example has stable blocks 1–5 and a changing timestamp/user-message block 6. With the only breakpoint on block 6, the first request writes an entry that includes the timestamp. The next request changes that prefix. Looking backward to block 5 does not help: no entry was written there.

The correction is to mark block 5, not to assume lookback discovers and caches stable material automatically. Everything up to and including that block must remain identical.

Apply that boundary to CometAPI Messages

CometAPI’s Cache prompts example already demonstrates the useful separation: reference text in a system content block with cache_control, and a question in messages. It uses the Anthropic SDK against https://api.cometapi.com, via POST /v1/messages.

For that integration, keep the reference block stable and put changing request context after its breakpoint. The relevant request-body fragment is:

{
  "system": [
    {
      "type": "text",
      "text": "<unchanged reference material>",
      "cache_control": {"type": "ephemeral"}
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "<this request's question and any changing timestamp>"
    }
  ]
}

This is a structural fragment, not a complete runnable request. Replace the placeholders with actual content, retain the model and other required fields from the CometAPI example, and use a reference prefix that meets the selected model’s minimum cacheable length. The short placeholder above would not establish a meaningful cache test. CometAPI’s cache example uses claude-sonnet-5; this placement advice is about its documented Claude Messages format, not a claim of cache compatibility across other model APIs.

Test placement, not several variables at once

My suggested check is two sequential requests through that same CometAPI Messages integration:

  1. Send the reference with the breakpoint on its last stable block. Wait for the completed response and record its usage counters.
  2. Promptly send another request, changing only the question after that breakpoint. Keep the model, reference, thinking settings and effort configuration unchanged.
  3. Compare cache_creation_input_tokens and cache_read_input_tokens. CometAPI documents the former as tokens written to cache and the latter as tokens read from it. A positive read counter is evidence of reuse; another write alone is not.

If reads remain zero, inspect the entire prefix—not just the marked block—for changes. Then check the selected model’s minimum length and the timing between requests. Anthropic documents a default five-minute ephemeral lifetime and notes that a cache entry becomes available only after the first response begins. A prompt below the minimum can skip caching without an error, so zero writes and zero reads is a different clue from repeated positive writes.

This is a documentation-based diagnostic, not a reported CometAPI benchmark. Correct placement removes one avoidable source of misses; it does not establish a hit, a bill reduction, or a latency improvement until the actual integration is measured. For this workload, the first decision is simple: write an entry for the reference you intend to reuse, rather than for the reference plus today’s question.

A useful implementation detail is to treat the breakpoint as a contract boundary in the request builder, not as a tuning flag scattered through call sites. Build the reusable system/reference prefix from a canonical representation, append the per-request question only after that boundary, and log a redacted fingerprint of the prefix plus the two cache counters. That makes it possible to distinguish “the question changed as intended” from an accidental change to the supposedly stable prefix (for example, reordered JSON, a timestamp in system text, or altered thinking settings).

I would also make the two-request check a prerequisite for enabling any cache-based cost assumption. The first response should establish that the write completed; the second should be sent within the documented ephemeral window and vary only the post-breakpoint question. A zero read counter should route to diagnosis rather than automatic retries: compare the prefix fingerprint, confirm the selected model’s minimum length, and check whether the first response had started. This is especially important for agents that retry or parallelize calls, since a retry with a different tool schema or hidden context can invalidate the intended prefix while still looking like the same task.

The same design gives a safe fallback: if the read signal remains absent, the system can continue without assuming cache savings. The breakpoint recommendation is therefore an observability and request-shaping decision for the documented Claude Messages integration, not evidence that every CometAPI model or workload will cache successfully.