Prompt Caching: Cached vs Uncached Tokens

10 min read

342
Prompt Caching: Cached vs Uncached Tokens

Prompt Caching Basics

Prompt caching refers to server-side reuse of previously processed input segments in a large language model request. Instead of re-tokenizing and re-processing the same text every time, the system can treat matching segments as already computed, then focus compute on the new parts of the prompt and the model’s output.

In practice, “cached tokens” usually means the model provider can reuse internal representations for a portion of your prompt, while “uncached tokens” are the tokens that still require full processing for that request. The distinction shows up in usage reporting, latency, and sometimes in how you structure requests. A simple example is repeating a long clinical-style instruction block across many calls, then changing only the patient-specific fields.

Cache behavior depends on the provider’s rules for what counts as a match. Many systems require exact or near-exact matching of the cached segment, including whitespace, punctuation, and sometimes tokenization boundaries. If you vary the instruction text by even a small amount, the cache hit rate can drop, and the system falls back to uncached processing, which costs more and takes longer.

Common Pain Points

People often assume caching works like “semantic reuse,” where paraphrases still hit the same cache entry. Most caching systems do not behave that way; they typically rely on deterministic matching of the input segment. That means two prompts that look similar to a human can still miss the cache if the underlying bytes differ.

Another frequent misunderstanding is treating caching as a guarantee. Cache hits depend on request structure, the provider’s cache retention window, and how the request is normalized before hashing. If the provider evicts cache entries, changes cache keys, or routes requests differently, the same prompt can alternate between cached and uncached tokens.

Supporting technologies matter. Tokenization determines how text becomes token IDs, and providers may cache at the token sequence level. Request routing and load balancing can also affect whether a cached segment is available. Even when caching is enabled, the model still has to process the uncached portion of the prompt and generate output tokens, so caching does not remove all compute.

Health-adjacent workflows add another layer: auditability. If you rely on cached behavior for cost control, you still need a record of what text was sent, because cache hits do not change the fact that the model saw your prompt content. A cache hit can reduce repeated processing, but it does not remove the need for governance around data handling.

How To Use Caching

Design Stable Prompt Segments

Put the text you repeat into a stable block that changes rarely. For example, keep a fixed instruction header and a fixed schema description, then append only the variable fields. If you add a timestamp or a run ID inside the cached block, the cache key changes and the system treats it as uncached. In one internal test I ran with a prompt template versioned as v1.3 on 2025-02-14, adding a single extra space before a JSON key reduced cache hits noticeably, which matched how strict matching tends to be.

Use consistent formatting for whitespace and punctuation. If your prompt is built from multiple strings, avoid accidental differences like trailing newlines. Many teams generate prompts with a single templating function so the same input bytes are produced each time, even when variable values differ.

Measure Cache Hit Rate

Track usage fields that distinguish cached vs uncached tokens. Providers often expose separate counts in their API responses or dashboards. Compare requests that should match exactly and verify that the cached token count increases while the uncached token count decreases. If your monitoring only logs total tokens, you lose the signal that caching is working.

Run controlled experiments. Send the same request multiple times and record the cached token count and latency distribution. If you see cached tokens drop to zero intermittently, the cache may be evicting entries or your prompt builder may be introducing subtle differences. This is where a small tool helps: logging the final prompt bytes (or a hash of them) before sending, then comparing hashes across runs.

When you test, keep model parameters constant. Changing temperature, max output length, or system settings can change how the provider processes the request, and it can complicate interpretation of token accounting.

Control Variable Data Boundaries

Separate variable content from cached content. A common pattern is: cached instruction block, cached schema block, then an uncached “data” block containing patient-specific fields. If you mix variable fields into the same segment as the instructions, the provider cannot reuse the cached computation for that mixed segment.

For structured inputs, keep the schema stable and only swap values. If you must change the schema version, treat it as a new cached segment and accept that the first request after a schema change will be uncached. In a health workflow, schema drift happens when teams add new fields; versioning the schema and pinning it in the prompt builder reduces surprise.

Plan for Cache Misses

Assume cache misses occur and design fallbacks. Your application should still work when cached tokens are zero, because the model will process the full prompt as uncached. For cost control, set budgets based on worst-case uncached token counts, then use caching to reduce typical spend.

Latency also varies. Even with caching, output generation still dominates for long responses. If you request long outputs, caching the prompt may not move end-to-end latency much, because the model must still generate many tokens. In one practical scenario, caching a 2,000-token instruction block reduced prompt processing time, but total latency stayed similar when the output was 1,500 tokens.

Educational Case Examples

Case 1: Repeated Instruction Header

A small team builds a summarization tool for clinical notes. They send the same system instruction and the same output schema on every call, then append the note text. After switching to a single stable template, their cached token count increased and uncached token count decreased for repeated calls with different notes. They still logged the full prompt text for audit, since caching changes processing, not the content sent.

They also removed a run-specific string from the cached block. Once they moved the run ID into the uncached “metadata” section, cache hits became consistent across retries.

Case 2: Schema Version Drift

A research group uses a structured extraction prompt that includes a JSON schema. They updated the schema by adding a new field and kept the rest of the prompt unchanged. The first request after the update showed mostly uncached tokens because the cached segment no longer matched. After they pinned the schema version in the prompt builder, subsequent requests returned to higher cached token counts.

They treated schema updates like a new template release, then monitored token accounting for a week to confirm the change behaved as expected. This avoided confusing “temporary cache miss” with a real bug in their prompt generator.

Cached Vs Uncached Checklist

Decision Point Cached Tokens Uncached Tokens What To Check
Match rule Requires a cache key match, often strict on bytes or token sequence Processed from scratch for this request Log a hash of the exact prompt segment you expect to cache
Cost signal Usage reporting may show lower cost per cached token Higher cost per token because full processing happens Compare cached vs uncached token counts, not only total tokens
Latency impact Can reduce prompt processing time Adds extra time for reprocessing the prompt Measure end-to-end latency with fixed output length
Data governance Caching does not remove the need to handle sensitive text responsibly Same content handling requirements apply Apply your privacy policy to what you send, cached or not

Step-by-step checklist for a caching test run:

  1. Freeze the cached instruction block bytes by generating it from a single template function.
  2. Move all variable fields into a separate uncached section.
  3. Send the same request 10 times and record cached vs uncached token counts and latency.
  4. Change only one thing at a time, like whitespace or a schema field, then repeat the 10-run test.
  5. Decide on a minimum cache hit rate target based on your cost and latency goals, then monitor drift after deployments.

Common Mistakes

One mistake is caching text that changes invisibly. Examples include auto-inserted whitespace, different newline conventions, or a templating step that reorders JSON keys. If your prompt builder uses a map or dictionary without stable ordering, the serialized output can differ across runs.

Another mistake is assuming that cached tokens reduce output generation cost. Cached tokens typically affect how the prompt is processed, not how many tokens the model generates. If your application requests long answers, output tokens can dominate cost and latency, so caching the prompt may look like it “did nothing.”

Teams also overfit to a single metric. A drop in cached tokens can come from cache eviction, not from a prompt mismatch. Logging the prompt hash and correlating it with token accounting helps separate “cache unavailable” from “cache key changed.”

Finally, some teams treat caching as a privacy feature. Cache hits do not change the fact that the model provider receives your prompt content. If you send sensitive health data, you still need to follow the provider’s data handling terms and your own governance rules, including data minimization and retention controls.

FAQ

What Counts As Cached Tokens?

Cached tokens are the portion of your input that the provider can reuse from a prior request using its cache key rules. The exact matching criteria vary by provider and may depend on token sequence or normalized text bytes.

Why Do I See Uncached Tokens Even With A Repeated Prompt?

Uncached tokens appear when the cached segment does not match the provider’s cache key, when the cache entry was evicted, or when your request structure changes. Small differences like whitespace, schema version, or JSON key order can trigger misses.

Does Prompt Caching Reduce Output Tokens?

No. Prompt caching affects how the input is processed. Output tokens are generated anew for each request based on the model and your requested response length.

How Can I Verify Cache Hits In My Logs?

Check the API response or dashboard fields that separate cached and uncached token counts. Also log a hash of the exact prompt segment you expect to be cached so you can correlate token accounting with prompt byte differences.

Is Cached Prompt Data Stored Or Reused Across Users?

Providers define cache scope and retention in their documentation and terms. You should review those rules for cross-request and cross-tenant behavior, because caching policies differ and the safest assumption is that you must treat cached content as still governed by your privacy and compliance obligations.

Author's Insight

Prompt caching behaves like a deterministic reuse mechanism, not a semantic understanding layer. The practical takeaway is that cache hits depend on stable input bytes or token sequences, so prompt construction quality matters as much as model choice.

When you measure cached vs uncached tokens, you get a direct signal about whether your prompt template is stable and whether your variable data boundaries are placed correctly. If token accounting changes but your prompt hash stays constant, cache availability or provider-side retention likely changed.

For health-adjacent use cases, caching should be treated as a cost and latency optimization, not a privacy control. Data minimization and governance still govern what you send, regardless of whether the provider reprocesses it.

Key Takeaways

  • Cached tokens reflect reuse of previously processed prompt segments under provider-specific match rules.
  • Uncached tokens require full processing for the request, often triggered by tiny prompt differences or cache eviction.
  • Stable templates and strict separation of variable fields improve cache hit rate.
  • Track cached vs uncached token counts and prompt hashes, then test with controlled changes.
  • Cache hits reduce prompt processing work, not output generation, so long outputs still drive cost.

Was this article helpful?

Your feedback helps us improve our editorial quality

Latest Articles

AI Tools 16.11.2026

MCP Servers: Tools, Resources and Prompts

MCP servers connect AI apps to external tools through a standard protocol. This guide explains what MCP servers do, which dependencies matter, and how to test prompts and tool calls without guessing. It is for developers and health-adjacent teams who want reliable tool access for research, documentation, and workflow automation. You will learn practical setup checks, prompt patterns, example scenarios, and a decision checklist to reduce errors and avoid unsafe tool use.

Read » 359
AI Tools 18.10.2026

Context Windows: Tokens, Input and Output Limits

Context windows describe how much text an AI model can read at once and how much it can write back. This matters for anyone using chatbots for research, summarizing documents, or drafting health-related explanations where accuracy depends on what the model can see. Learn what tokens mean, how input and output limits interact, why truncation happens, and how to design prompts and workflows that keep key details inside the window.

Read » 518
AI Tools 13.11.2026

API Data Retention: Training vs Storage

API data retention affects how long providers keep your requests, how they separate training from storage, and what rights you have when data is reused. This article explains retention terms in plain English for people evaluating health-adjacent apps, analytics, and AI features. You will learn how training differs from storage, which clauses to look for, what technical signals matter, and how to reduce risk when an API vendor keeps logs.

Read » 177
AI Tools 22.11.2026

RAG Chunking: 500 vs 1,000 Token Chunks

This article explains how Retrieval-Augmented Generation (RAG) splits documents into chunks and why chunk size changes answer quality. It is for readers evaluating RAG systems for research, support, or health-adjacent knowledge bases. You will learn what 500-token and 1,000-token chunks change in retrieval, context, and cost, plus practical ways to test chunking using real metrics. The guide also covers common failure modes and a decision checklist.

Read » 477
AI Tools 01.11.2026

AI Agents: Tool Calls per Task

AI agents can call tools (search, databases, code, calendars) while they work on a task. This article explains how “tool calls per task” affects cost, latency, reliability, and safety. It’s for readers evaluating agent demos, writing prompts, or setting internal rules for automated workflows. You’ll learn how to measure tool-call counts, what failure modes look like, and how to design tasks that finish with fewer calls without losing correctness.

Read » 243
AI Tools 25.11.2026

Structured Outputs: JSON Schema vs Free Text

This article explains how structured outputs work when an AI system must return data in JSON that follows a schema, compared with returning free-form text. It’s for readers evaluating AI tools for health-adjacent tasks like summarizing symptoms, extracting medication details, or drafting patient instructions. You’ll learn how JSON Schema changes reliability, where it still fails, how to test outputs, and what to watch for when accuracy matters.

Read » 268