Log in·Sign up
BestRelay

Back to the Journal

Stable Prefixes Make Long Conversation Caches Pay

Start by separating repeated context from conversation growth

A long conversation does not automatically make prompt caching economical. Savings come from repeatedly reading eligible cached input after paying any applicable write premium. A large context used once can cost more to cache than to process normally. The first task is therefore to identify material that will survive several requests unchanged.

Divide the input conceptually into stable instructions, reference material, and growing conversation history. Product rules, tool definitions, and a shared technical specification are promising candidates. A fresh user question belongs near the end. Keep timestamps, request identifiers, and other changing details out of the reusable prefix whenever the application permits.

Check provider rules before choosing cache boundaries

Providers differ in cache eligibility, minimum input length, retention, and whether applications explicitly mark cache boundaries or receive automatic caching. Treat these as model-specific constraints, not universal API behavior. Confirm support through current provider documentation and validate it with reported usage. A request completing successfully does not prove that its input was cached.

This distinction matters when routing across model families. BestRelay is a quality-first API relay covering Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok, and more. It forwards each request to the official model named in that request without substitution. That preserves model selection, but cache behavior still depends on the selected provider and model.

Calculate the reuse needed to repay writes

Build the comparison around one eligible prefix. Imagine that processing it normally costs ten accounting units, writing it costs twelve, and reading it costs one. These are illustrative numbers, not a price quote. The initial write costs two units more than ordinary processing; each subsequent read saves nine units. One successful reuse therefore repays the premium.

For your actual rates, subtract the ordinary input cost from the total cache-write cost. Divide that premium by the savings from one cache read. Then round up to a whole number of reads. Compare equivalent token volumes, and verify whether the published write price represents the total charge or an additional surcharge. Output charges remain outside this comparison.

Arrange the prefix to survive successive turns

Place reusable content before changing content, subject to the API's message and tool requirements. Preserve ordering and serialization wherever possible. Reordering tool definitions, changing whitespace inside reference text, or inserting a timestamp near the beginning can reduce reuse. Providers may match prefixes differently, so test rather than assuming that semantically identical inputs share a cache entry.

For growing conversations, retain stable earlier messages when feasible. A newly appended turn may leave an earlier prefix reusable while introducing uncached tokens. Explicit-cache APIs may require deliberate boundary placement to capture that benefit. Avoid repeatedly rewriting the entire history merely to improve its formatting.

Match retention to the next likely turn

Choose an available retention option based on observed user behavior. An active debugging session may produce several requests within minutes, while an asynchronous review may pause for hours. A higher write charge for longer retention only helps when enough later requests actually arrive within that window. Expiration before reuse turns the expected saving into an unrecovered expense.

Conversation summaries need similar discipline. Summarization can reduce future input, but replacing history can also invalidate reusable context. Prefer deliberate checkpoints over automatic rewrites after every message, and evaluate summary generation costs alongside any lost cache reuse.

Measure actual savings before expanding the rollout

Record ordinary input, cache-write, cache-read, and output tokens separately where the provider reports them. Compare total conversation cost against a realistic uncached baseline. Track latency too, but do not treat faster responses as proof of lower charges.

BestRelay bills pay-as-you-go from provider-reported token counts, with cache reads and writes priced separately. It works with Claude Code, Codex, Gemini CLI, and any OpenAI SDK. Create a BestRelay account to test a representative conversation. Members also earn a referral commission when invited users top up; keep that incentive separate from your caching evaluation.

Expand only after real sessions demonstrate enough eligible reads to recover write costs. The winning pattern is not maximum cached volume, but stable context reused often enough before expiration.

Want to try the models discussed here? Sign up