By NHI Mgmt Group Editorial TeamDomain: AI SecuritySource: ngrokPublished December 16, 2025

TL;DR: Prompt caching in LLMs reuses key and value tensors, not model outputs, which cuts latency and lowers token costs for long prompts, according to ngrok's explanation of OpenAI and Anthropic API behaviour. That makes caching a performance control with governance implications for AI systems, especially where prompt reuse, access patterns, and sensitive context need tighter oversight.


At a glance

What this is: This is an explainer on how KV caching works in LLM inference and why it reduces cost and latency by reusing attention-state data.

Why it matters: It matters because teams building AI applications need to understand what is cached, how long it persists, and how that affects control, privacy, and operational risk.

By the numbers:

👉 Read ngrok's explanation of KV caching in LLM inference


Context

KV caching is a performance optimisation in LLM inference, but it also exposes a governance question: what state is being reused between requests, and what does that mean for sensitive prompts in production AI systems? In practice, the control issue is not whether the model repeats an answer, but whether intermediate attention state persists long enough to change cost, latency, and exposure patterns.

For teams operating AI applications, this is relevant to AI security, data handling, and access governance because cached inference state sits inside the runtime boundary of the model provider. Where prompts contain credentials, private context, or regulated data, practitioners need to understand the lifecycle of cached material and how it aligns with broader AI and identity controls.

That makes this article a useful bridge between LLM architecture and operational governance. Its starting point is typical for a technical explainer, but the implications extend into policy, monitoring, and data-risk decisions for AI programmes.


Key questions

Q: How should security teams govern prompt caching in enterprise AI applications?

A: Treat prompt caching as a runtime governance issue, not just a performance setting. Define which prompt classes may be cached, exclude secrets and regulated data where possible, and align retention assumptions with your data handling policy. If the provider can reuse context for minutes, that reuse window must be covered by classification, logging, and approval controls.

Q: Why does KV caching matter for AI security and data risk?

A: KV caching matters because it reuses intermediate attention state derived from the prompt, which can keep sensitive context operationally relevant after the first request. That affects latency, cost, and exposure boundaries. Teams should assume cached state can outlive a single call and design prompt controls accordingly.

Q: What do teams get wrong about cached input tokens in LLMs?

A: Many teams assume cached input tokens mean the model is storing and replaying answers. It does not. The provider is reusing attention tensors, so the output can still vary while the runtime benefits from prior computation. That distinction is critical for policy design and for understanding what data may remain resident.

Q: How can organisations reduce risk when using long-context LLM APIs?

A: Separate durable instructions from sensitive content, limit what enters prompts, and set a clear rule for which workflows can tolerate provider-side reuse. Long-context systems need explicit governance because efficiency gains can hide retention and exposure assumptions that would otherwise be visible in a traditional application flow.


Technical breakdown

How KV caching works inside transformer attention

In a transformer, each new token is processed against the prior context through attention. The expensive part is recomputing the key and value matrices for the full prefix on every step. KV caching stores those intermediate tensors so the model can reuse them when generating the next token. That is why caching accelerates long prompts: the model still evaluates the new token, but it does not rebuild the entire attention history from scratch. The result is lower compute cost and lower time-to-first-token latency without changing the model output path.

Practical implication: AI teams should treat cached prompt state as part of the inference surface and document how long provider-side state can persist.

Why cached tokens do not mean cached answers

A cached prompt does not store a finished response for replay. It stores the attention state derived from the prompt prefix, which is then combined with the new token to produce the next output. That is why repeated API calls can return different responses even when the usage report shows cached input tokens. The cache improves efficiency by skipping repeated computation, not by short-circuiting generation. This distinction matters for governance because the security question is about reuse of context, not reuse of content. It also explains why model randomness settings do not invalidate cache utility.

Practical implication: teams should avoid assuming cache hits imply deterministic behaviour or reduced data sensitivity.

Why cache reuse creates an operational control boundary

Providers may cache prompt prefixes for a short window and may match partial prefixes, which means the cache behaves like an optimisation layer with its own lifecycle. In operational terms, that creates a boundary where latency and cost are influenced by prior traffic patterns. For AI security programmes, the boundary matters because it can affect observability, prompt reuse policy, and how quickly sensitive context is discarded from memory-backed systems. The architecture is efficient, but governance has to account for the fact that the reused state is not just a performance detail.

Practical implication: define prompt-handling rules for sensitive data and verify provider retention assumptions against your AI governance policy.


NHI Mgmt Group analysis

KV caching introduces an AI governance gap, not just a performance feature. The article shows that providers reuse intermediate attention state to reduce cost and latency, but that also means AI teams are operating with a runtime optimisation that persists beyond a single token generation step. In governance terms, this is a state-reuse problem that belongs in AI security reviews, not only engineering discussions. Practitioners should treat cache behaviour as a control consideration for sensitive prompts and regulated data.

Cached inference state is a form of operational memory that identity teams cannot ignore. Where AI systems consume secrets, internal context, or user data, the fact that a provider may retain reusable attention tensors for minutes creates a new boundary for policy enforcement. That intersects with identity and access governance because the trust decision is no longer only about who can call the API. It is also about what context the service can retain, reuse, and potentially amplify across requests.

Prompt caching sharpens the case for named AI runtime governance. The useful concept here is inference state persistence: the short-lived retention of model context that improves performance while expanding the window in which sensitive data remains operationally relevant. This should be governed alongside data classification, secret handling, and logging controls. Teams that ignore the runtime layer will miss the real control point.

The main lesson is that model efficiency and control design now move together. Organisations that want the cost benefits of long-context AI need explicit rules for retention, prompt composition, and provider-side reuse. That means AI governance, IAM, and data security teams should align on what can enter prompts, who can submit them, and how fast that context must be discarded in policy and practice.

What this signals

Inference state persistence: AI teams should now treat provider-side caching as a policy object, because the runtime layer can preserve sensitive context long enough to matter operationally. That makes prompt design, retention rules, and secret handling part of the same governance conversation, not separate workstreams.

Programmes that already struggle with secret sprawl should assume the same discipline applies to AI prompts. The operational lesson is simple: if a system can retain and reuse context, it needs classification, expiry, and ownership just like any other sensitive asset.

For identity and access teams, the practical shift is to extend control reviews from who can call the model to what the model is allowed to remember. That is where IAM, data handling, and AI governance start to overlap in a measurable way.


For practitioners

  • Define prompt sensitivity tiers Classify prompts by whether they may contain secrets, customer data, or internal-only context, and prohibit caching for the highest-sensitivity tiers where provider controls allow it.
  • Review provider cache retention windows Document the stated cache lifetime for each model provider and compare it with your data handling policy, especially for regulated or confidential workflows.
  • Separate reusable prefixes from sensitive payloads Design prompts so stable, reusable instructions are isolated from variable sensitive content, reducing the chance that private material is carried into cached state.
  • Align AI access policy with runtime state reuse Extend AI governance reviews beyond authentication to include who can send prompts, what data can be embedded, and what provider-side reuse is acceptable.

Key takeaways

  • KV caching reuses attention state, not answers, so the control problem is runtime reuse of context rather than response replay.
  • The performance benefit is real, but so is the governance impact when sensitive prompts can remain operationally relevant across requests.
  • AI programmes should define prompt retention rules, cache eligibility, and ownership before long-context usage becomes business critical.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST AI RMF, NIST AI 600-1 and NIST CSF 2.0 set the technical controls, while ISO/IEC 27001:2022 define the regulatory obligations.

FrameworkControl / ReferenceRelevance
NIST AI RMFMANAGEAI runtime caching affects operational risk management and prompt handling decisions.
NIST AI 600-1Long-context AI workflows require controls around model use and data exposure.
NIST CSF 2.0PR.DS-1Prompt content containing sensitive data maps to data security and handling expectations.
ISO/IEC 27001:2022A.5.12Information classification is relevant where prompts may include confidential or regulated data.

Set policies for prompt retention, sensitive data handling, and provider-side reuse under MANAGE.


Key terms

  • Kv Caching: KV caching is an LLM inference optimisation that reuses key and value tensors computed from earlier prompt tokens. It reduces repeated attention work for long prompts, improving latency and cost efficiency without changing the model’s output logic.
  • Attention State: Attention state is the internal representation an LLM uses to relate each new token to prior context. It is built from key, query, and value computations and is central to how the model preserves meaning across a generation sequence.
  • Inference State Persistence: Inference state persistence is the short-lived retention of model context or intermediate tensors during generation. In governance terms, it matters because reused state can extend the operational life of sensitive prompt content beyond a single API call.
  • Prompt Retention Policy: A prompt retention policy defines what types of input may be sent to an LLM, whether caching is allowed, and how long provider-side or application-side context may remain accessible. It is a governance control for sensitive AI workflows.

What's in the full article

ngrok's full article covers the architectural detail this post intentionally leaves at a governance level:

  • Step-by-step walkthrough of tokenizer, embedding, attention, and feedforward stages in the LLM inference loop
  • Matrix-level explanation of how key and value tensors are derived and reused across tokens
  • Hands-on comparison of OpenAI and Anthropic caching behaviour, including cache hit patterns and latency effects
  • Technical examples showing why temperature settings do not invalidate cached prompt reuse

👉 The full ngrok article covers transformer mechanics, cache reuse, and provider latency behaviour in detail.

Deepen your knowledge

The NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, secrets management, IAM, and machine identity security. It helps practitioners connect identity controls to the broader security programmes that now include AI runtime governance.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 19, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org