Skip to content

GLM-5.2 Prompt Caching: How to Get and Measure Cache Hits

Independent research — not an official Z.ai publication.Identity and provider disclosure

GLM-5.2 prompt caching flow: stable prompt prefix is automatically matched, cached token usage is reported, and a request falls from $0.1840 with no hit to $0.0928 at an 80 percent input hit

Official behavior and prices on this page were checked July 19, 2026. GLM52.ai did not send live cache requests or run a latency benchmark.

Prompt caching has two separate jobs: reuse provider-side input computation and charge eligible input at a lower rate. It does not increase GLM-5.2’s context window, compress conversation history, or make generated reasoning and output free.

If you operate SGLang yourself, do not use this billing guide to size host RAM. The separate GLM-5.2 HiCache audit calculates per-rank L2 KV and DSA indexer memory, then stages optional L3 storage. Provider prompt caching and self-hosted KV offload are different systems with different evidence.

The practical problem is therefore not “does GLM-5.2 support caching?” It does. The problem is how to preserve a reusable prefix, verify what the provider counted, and turn the measured hit rate into a budget.

  1. Quick facts
  2. How automatic context caching works
  3. What cached_tokens proves
  4. Cost at five cache-hit rates
  5. Build a stable prefix
  6. Caching in tool and agent loops
  7. What the official page does not promise
  8. Provider routes can behave differently
  9. Which workloads benefit?
  10. Run a small cache acceptance test
  11. Common questions
  12. Sources and method
Question Documented answer Operational consequence
Is caching supported? Yes, including GLM-5.2 A repeated prefix can earn cached-input billing
Is a manual cache flag required? No in the official examples; matching is implicit Request layout matters more than a cache-control parameter
How do you verify a hit? Read usage.prompt_tokens_details.cached_tokens Do not infer hits from repeated text or a faster response
Fresh input price $1.40 per million tokens Applies to input not reported as cached
Cached input price $0.26 per million tokens An 81.4% input-token discount at a full hit
Output price $4.40 per million tokens Caching input does not discount generated output
Exact TTL or minimum prefix Not stated for GLM-5.2 on the checked official caching page Measure the live route; do not hard-code an invented threshold

The provider can update prices, expiry behavior, or route semantics. Keep the checked date beside any production budget and alert when response telemetry changes.

The official context-caching guide says the service identifies input content that is identical or highly similar to previous requests and reuses earlier computation. It names three common cases: a stable system prompt, repeated task instructions, and conversation history.

Its GLM-5.2 examples follow a consistent layout:

request 1 = stable system prompt + changing question A
request 2 = stable system prompt + changing question B

The long-document example places the unchanged document in the system message, then asks different questions. No explicit cache-creation or cache-read parameter appears. The first request warms reusable computation; a later matching request can report cached tokens.

“Automatic” does not mean “guaranteed.” The same official guide warns that exact content has the highest hit likelihood, light formatting differences can affect the result, and expired cache entries are recomputed. Treat caching as observed service behavior, not a property of any string that appears twice.

The evidence field is:

{
"usage": {
"prompt_tokens": 100000,
"completion_tokens": 10000,
"prompt_tokens_details": {
"cached_tokens": 80000
}
}
}

This example means 80,000 of 100,000 input tokens were reported as cached. It does not say why the other 20,000 missed, how long the entry will remain reusable, or whether another provider route uses the same cache.

Calculate the realized hit rate from input tokens, not total tokens:

hit rate = cached_tokens ÷ prompt_tokens
= 80,000 ÷ 100,000
= 80%

Log at least the model ID, provider route, request template version, prompt tokens, cached tokens, output tokens, latency, retry count, and acceptance result. A low bill is not useful if the request fails or a changed prefix silently destroys the hit rate.

Z.ai’s pricing page lists GLM-5.2 at $1.40/M fresh input, $0.26/M cached input, and $4.40/M output.

If h is the measured input hit rate:

effective input price per million
= (1 − h) × $1.40 + h × $0.26
= $1.40 − $1.14h

A full input hit discounts input by 81.4%: 1 − ($0.26 ÷ $1.40). It does not discount output. For a request with 100K input and 10K output:

Input hit rate Fresh input Cached input Output Total request Saving
0% $0.1400 $0.0000 $0.0440 $0.1840 0.0%
50% $0.0700 $0.0130 $0.0440 $0.1270 31.0%
80% $0.0280 $0.0208 $0.0440 $0.0928 49.6%
90% $0.0140 $0.0234 $0.0440 $0.0814 55.8%
100% $0.0000 $0.0260 $0.0440 $0.0700 62.0%

The gap between 81.4% input savings and 62.0% total savings at a full hit is the unchanged $0.044 output line.

At larger volume, an 80% hit on one billion monthly input tokens changes input cost from $1,400 to $488:

200M fresh × $1.40/M = $280
800M cached × $0.26/M = $208
realized input total = $488
input saving = $912, or 65.1%

Use the GLM-5.2 API cost calculator to add requests, retries, output, and provider routes. It models arithmetic; response telemetry must supply the hit-rate input.

Put stable, shared material first:

  1. system policy and response contract;
  2. tool definitions with a stable order;
  3. long reference documents or repository instructions;
  4. reusable examples;
  5. changing user request, timestamp, retrieved facts, or task payload.

Avoid inserting a request ID, current time, randomized tool order, changing whitespace, or fresh retrieval block before the reusable material. A small early change can shift the rest of the prefix and reduce reuse.

Version the prefix deliberately. When a policy or tool schema changes, update a template version in logs and expect a cold request. Do not preserve stale instructions for the sake of a cache hit. Correctness and policy freshness come before the discount.

Keep secrets out of shared prompt templates when they are not required. Caching is a provider-side service feature, so privacy and retention terms still matter. Our GLM-5.2 API provider comparison separates route-level privacy, observability, and model access.

Agent loops can reuse a large system prompt and tool catalog on every turn. They can also destroy reuse by placing dynamic tool results or per-turn metadata too early.

A January 2026 prompt-caching study tested OpenAI, Anthropic, and Google agents—not GLM-5.2. Across those models it reports 41–80% cost reductions and 13–31% time-to-first-token improvements. It also found that stable system-prompt boundaries could be more consistent than naive full-context caching with changing tool results.

That paper supports the layout principle, not a GLM performance claim. Z.ai’s automatic matcher, its expiry policy, and a gateway’s routing can behave differently. Measure GLM itself before promising latency or savings.

Reasoning adds another billing line. Cached input can reduce prompt cost, while newly generated reasoning remains output work. Our GLM-5.2 reasoning-effort guide explains why max effort can still dominate a warm agent turn’s cost.

The checked official GLM-5.2 caching documentation does not publish:

  • a model-specific minimum number of tokens required for activation;
  • an exact cache lifetime;
  • a guaranteed hit percentage;
  • a guaranteed latency reduction;
  • a promise that lightly edited content will match;
  • permanent zero-cost cache storage.

The pricing page labels cache storage as limited-time free. Budgeting it as permanently free would turn a temporary line item into an unsupported promise.

Do not import thresholds or TTLs from OpenAI, Anthropic, or another model host. A client may expose an OpenAI-compatible request body while using different routing, billing, telemetry, and cache eviction underneath.

The official examples describe Zhipu/Z.ai’s route. A third-party GLM-5.2 endpoint may use another checkpoint precision, context limit, cache implementation, cache price, storage rule, or usage field. A balanced gateway can also switch the serving provider.

Before choosing a route, require a short proof:

  • the exact GLM-5.2 model ID and context limit;
  • cached_tokens or equivalent response telemetry;
  • fresh, cached, output, write, and storage prices;
  • cache scope, expiry, and privacy terms;
  • behavior after a model or template version changes.

Caching is most valuable when the input is large, early content remains stable, and many requests reuse it:

  • coding agents with a fixed policy and tool catalog;
  • repeated questions over one long manual or contract;
  • batch classification with one rubric and many records;
  • support automation with a stable product knowledge prefix;
  • multi-turn work where history grows by appending new turns.

It matters less for a single short request, a template rewritten on every call, a route that does not expose hit telemetry, or a workload whose output cost dominates.

Never optimize hit rate alone. A shorter curated prompt with fewer cached tokens can cost less and perform better than a huge stale prefix. Rank designs using accepted-result rate, total spend, latency, and failure severity.

Create 10 to 20 requests that use one versioned stable prefix and different final tasks. Send a cold request, then the warm set. Do not publish a conclusion from one pair.

For each response, record:

route, model, template_version, prompt_tokens, cached_tokens,
completion_tokens, latency_ms, retry_count, accepted

Compare three layouts:

  1. stable system prompt only;
  2. stable prompt plus tools or reference document;
  3. the same reusable material with dynamic fields inserted near the beginning.

The third layout is a deliberate miss-risk control. If the first two show no cached tokens, check request identity, model route, prefix order, formatting, elapsed time, and provider documentation before assuming a billing defect.

Yes on the documented Zhipu/Z.ai route. The official examples do not send a manual cache-control field. The provider identifies reusable input and reports the realized cached-token count.

Read usage.prompt_tokens_details.cached_tokens. Divide it by usage.prompt_tokens to calculate the input hit rate. Do not divide by total tokens because output is not cacheable input.

Does repeated text guarantee the $0.26 rate?

Section titled “Does repeated text guarantee the $0.26 rate?”

No. The official guide says exact content has the highest hit likelihood, formatting changes can matter, and expired content is recomputed. Only reported cached tokens justify cached-input billing in an estimate.

Does caching make reasoning or output cheaper?

Section titled “Does caching make reasoning or output cheaper?”

It discounts eligible input. Newly generated reasoning and answer tokens remain output work at the route’s output price.

Does caching expand the one-million-token context window?

Section titled “Does caching expand the one-million-token context window?”

No. Cache reuse can reduce repeated processing and billing, but cached tokens still belong to the request context. Context management and prompt caching solve different problems.

At the checked direct rates, a full hit reduces the input-token price by 81.4%, from $1.40/M to $0.26/M. Total-request savings are lower whenever output, fresh input, tools, retries, or storage add cost.

Sources checked July 19, 2026:

The cost table is direct arithmetic from official rates. It holds total input and output tokens constant and changes only the fraction of input reported as cached. It excludes tax, retries, tools, cache-storage changes, gateway fees, and tokenization differences. GLM52.ai did not buy an endpoint, establish a cache, or measure latency for this article. The Novita path is sponsored and route-specific behavior must be verified.