GLM 5.3 Prompt Caching: Cut API Token Costs Fast
Nov 29, 2026

GLM 5.3 Prompt Caching: Cut API Token Costs Fast

Master GLM 5.3 prompt caching in 2026: drop input rates 81% ($1.40 to $0.26/1M, Flash $0.15 to $0.03/1M), structure static prefixes, and avoid cache misses.

If your agentic coding loops or long-document QA pipelines feel more expensive than expected, the culprit is almost never output length alone—it is missing GLM 5.3 prompt caching hits on repeated input context. Every time an agent re-sends a 40,000-token system prompt, tool schema list, and repository snapshot with a shifting timestamp at the top, you pay full fresh-input rates instead of an 80–81% discount.

This practical guide explains how GLM 5.3 prompt caching works on Z.ai's direct pricing schedule, how much it saves across flagship GLM 5.3 and GLM 5.3 Flash, the exact message layout that maximizes cache hit rates, and the five silent bugs that invalidate GLM 5.3 prompt caching in production. All rates are verified against Z.ai's official API pricing documentation as of November 29, 2026.

Verified Savings: GLM 5.3 Prompt Caching Pricing Table

Model TierFresh Input (per 1M)Cached Input (per 1M)Output (per 1M)Input Discount
GLM 5.3 (glm-5.3)$1.40$0.26$4.4081.4% off
GLM 5.3 Flash (glm-5.3-flash)$0.15$0.03$0.5080.0% off

Notice how aggressively GLM 5.3 prompt caching compresses repeated context: on flagship GLM 5.3, cached input drops from $1.40 to $0.26 per million tokens; on GLM 5.3 Flash, it drops to three cents per million tokens across a 1,048,576-token context window.

How GLM 5.3 Prompt Caching Works Under the Hood

GLM 5.3 prompt caching relies on exact prefix matching. When you send a request, the inference engine hashes leading token blocks starting from the very first token of your system prompt and tool definitions. If a subsequent request shares the exact same leading token sequence while the prefix remains warm in cache, those matching tokens are billed at the cached input rate ($0.26/1M on GLM 5.3, $0.03/1M on Flash) and skip redundant prefill compute—cutting both cost and time to first token.

Crucially, GLM 5.3 prompt caching stops matching at the first byte that differs. Even a single changed character on line 3 of your system prompt—such as Current time: 2026-11-29T09:14:02Z or a per-request UUID—busts the entire downstream prefix, forcing 100% of your static code files and tool schemas to re-bill as fresh input.

Worked Cost Math: Multi-Turn Agent With GLM 5.3 Prompt Caching

Consider a 15-turn coding agent session on flagship GLM 5.3 where each turn carries 80,000 tokens of static repo context and tool schemas plus 5,000 new tokens of diffs/messages and 3,000 output tokens:

  • Without GLM 5.3 prompt caching (0% hit rate):
    • 15 turns × 85K fresh input = 1.275M fresh input ($1.785) + 45K output ($0.198) = $1.983 per session.
  • With GLM 5.3 prompt caching (80K static prefix cached on turns 2–15):
    • Turn 1 fresh: 85K × $1.40/1M = $0.119.
    • Turns 2–15 cached: 14 × 80K = 1.12M × $0.26/1M = $0.2912.
    • Turns 2–15 new input: 14 × 5K = 70K × $1.40/1M = $0.098.
    • Output (45K): $0.198.
    • Total: $0.706 per session—a 64% total bill reduction (and a 72% input reduction) from GLM 5.3 prompt caching alone.

The Golden Message Layout for GLM 5.3 Prompt Caching

Structure every API call from most static to most dynamic so GLM 5.3 prompt caching hits on turns 2 through N:

  1. System instructions & coding rules (100% static): Never put dates, session IDs, or user names here.
  2. Tool/function JSON schemas (100% static, deterministic key order): Sort tool names and parameters identically on every call.
  3. Reference files, docs, or repo index (semi-static): Keep unchanging files grouped immediately after tool schemas so GLM 5.3 prompt caching reuses them across all turns in the session.
  4. Conversation history (append-only): Append new assistant and tool turns at the end; avoid rewriting earlier turns mid-session.
  5. Dynamic metadata & current user query (at the very end): Put timestamps, request IDs, and live git status in the final user message so they never invalidate earlier blocks.
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ZAI_API_KEY"],
    base_url="https://api.z.ai/api/paas/v4",
)

STATIC_SYSTEM = "You are a senior TypeScript engineer. Follow strict repository conventions."
STATIC_REPO_CONTEXT = "<static-files>...</static-files>"  # Unchanged across turns

response = client.chat.completions.create(
    model="glm-5.3",
    max_tokens=4096,
    extra_body={"thinking": {"type": "enabled"}, "reasoning_effort": "high"},
    messages=[
        {"role": "system", "content": STATIC_SYSTEM},
        {"role": "user", "content": STATIC_REPO_CONTEXT},
        {"role": "assistant", "content": "Repository context indexed. Ready for task."},
        {"role": "user", "content": "Timestamp: 2026-11-29T09:15Z. Fix pagination off-by-one in orders.ts."},
    ],
)

print("Usage:", response.usage)  # Inspect prompt_tokens_details.cached_tokens

Five Silent Bugs That Break GLM 5.3 Prompt Caching

When telemetry shows zero cached tokens, check these five common GLM 5.3 prompt caching killers:

  1. Dynamic timestamps in the system prompt. Move now() or request_id to the final user turn.
  2. Shuffled tool definitions. Dynamically filtering or re-ordering JSON tool arrays between turns changes the prefix hash and breaks GLM 5.3 prompt caching. Keep your tool registry fixed and sorted.
  3. Unstable JSON serialization. Pretty-printing or non-deterministic dict key ordering inside system context silently busts GLM 5.3 prompt caching.
  4. Rewriting middle conversation turns. Summarizing or editing turn 2 on every step invalidates everything from turn 2 onward. Only compact history at explicit checkpoints.
  5. Switching models mid-thread. Moving a session between glm-5.3 and glm-5.3-flash changes the KV cache namespace; keep one model per cached prefix, or run ingestion on GLM 5.3 Flash first and hand a compact summary to GLM 5.3.

Want to test long-context prompts interactively before optimizing your SDK? Try glm5.app/chat, compare GLM 5.3 and GLM 5.3 Flash, or check flexible credit packs on glm5.app/pricing.

Frequently Asked Questions

How much does GLM 5.3 prompt caching save per million tokens?

On Z.ai's official pricing schedule, GLM 5.3 prompt caching cuts flagship GLM 5.3 input from $1.40 to $0.26 per 1M tokens (81.4% off) and cuts GLM 5.3 Flash input from $0.15 to $0.03 per 1M tokens (80% off).

Does GLM 5.3 prompt caching reduce output token pricing?

No. GLM 5.3 prompt caching applies exclusively to matching leading input tokens. Output tokens—including reasoning traces—still bill at $4.40/1M on GLM 5.3 and $0.50/1M on GLM 5.3 Flash.

How can I verify that GLM 5.3 prompt caching is actually working?

Log response.usage on every API response and inspect the cached token counter (e.g., prompt_tokens_details.cached_tokens). If cached tokens stay at zero on turn 2, diff the exact serialized messages and tools payload between turn 1 and turn 2 to find what changed in the prefix.

Should I use GLM 5.3 prompt caching on both GLM 5.3 and GLM 5.3 Flash?

Yes. Combining GLM 5.3 prompt caching with GLM 5.3 Flash's 1M-token window drops repeated document or codebase context to $0.03/1M tokens, while using it on GLM 5.3 cuts multi-turn agent input spend by over 80%.

Sources

Start Using GLM 5 Today

Try GLM 5 free — reasoning, coding, agents, and image generation in one platform.