Safa API · aisafa.xyz

Claude Prompt Caching: How to Cut API Costs Up to 90% (2026 Guide)

发布于 2026-07-06 · Safa API

Claude prompt caching lets you reuse the unchanged part of a prompt — like a system prompt, long document, or tool definitions — across multiple API calls so you only pay full price for it once. Cached reads cost roughly 10% of standard input pricing, while writing to the cache costs about 1.25x on a 5-minute TTL (or 2x for a 1-hour TTL). For workloads with a large stable prefix and many repeat calls, that alone can cut input token spend by 70-90%.

How Claude prompt caching actually works

You mark part of your request as cacheable using a cache_control block in the Anthropic Messages API. The first call writes that content to a short-lived cache; every subsequent call within the TTL window reads from it instead of reprocessing the tokens from scratch. Nothing about the model's sampling changes — caching stores intermediate key/value state for the prompt prefix, not the generated output, so responses aren't degraded or made less accurate.

{
  "model": "claude-sonnet-4-6",
  "system": [
    {
      "type": "text",
      "text": "<your long system prompt, tool defs, or docs>",
      "cache_control": {"type": "ephemeral"}
    }
  ],
  "messages": [
    {"role": "user", "content": "What does section 4 say about refunds?"}
  ]
}

Anything after the cached block — the actual user message — is billed as normal, uncached input. Output tokens are never cached; only input tokens benefit. It's also worth noting caching is per-model: switching models mid-session invalidates the cache, since key/value state isn't portable across model weights.

The real math: when caching pays off

The catch most teams miss is the write premium. A 5-minute cache write costs 1.25x standard input price, and it expires if no request touches it for 5 minutes. So caching only saves money once you get enough reads per write to amortize that premium. As a rule of thumb:

Calls per cache windowNet effect
1 (no reuse)Costs more than no caching (write premium wasted)
2-3Roughly break-even
5+Meaningful savings, 40-60%+
20+ (long doc Q&A, agent loops)70-90% reduction on cached tokens

This is why prompt caching shines specifically for: RAG pipelines that reuse the same retrieved documents across follow-up questions, coding agents (like Claude Code or Cline) that resend the same system prompt and tool schema on every turn, and customer-support bots that cache a shared knowledge base. It does almost nothing for one-off, always-different prompts, and can actually cost more than no caching at all if your call volume per cache window is low.

Three ways to raise your cache hit rate

If your caching isn't saving what you expected, the usual causes are structural, not provider-related:

A cheaper way to run cached Claude, GPT, and Gemini calls

Prompt caching lowers the per-call bill, but the base rate you're multiplying still matters — and outside the US, actually getting a Claude API key is its own hurdle: a credit card that international billing systems accept, and a separate account for every model family you want to test. Safa API is an OpenAI-compatible relay built around exactly this pain point. One endpoint and one key route to Claude, GPT, and Gemini, it fully supports prompt caching (so everything above still applies), pricing runs lower than paying each vendor directly, and sign-up needs no credit card — Alipay works fine for topping up. If you're already restructuring prompts to cache well, pointing that same setup at a cheaper, no-card-required base URL is a five-minute change that compounds with the caching savings.

常见问题 / Frequently Asked Questions

Does prompt caching reduce output token cost too?

No. Caching only applies to input tokens — the part of the prompt sent to the model. Every output token is generated fresh and billed at the normal output rate regardless of caching.

Is a 5-minute or 1-hour cache TTL better?

Use the 5-minute TTL for interactive workloads where calls happen close together, like a live chat session or an agent loop. Use the 1-hour TTL for slower, asynchronous workflows — it costs more to write (2x vs 1.25x) but survives longer gaps between calls, so it's often cheaper overall if your call frequency is low.

Can I use prompt caching through a third-party relay instead of Anthropic directly?

Yes, as long as the relay passes through the cache_control parameter and bills cache reads/writes at the discounted rates rather than flat input pricing. Safa API supports this, so existing caching code that works against the native Anthropic API works unchanged against its endpoint.

立即开始使用 Safa API API 中转

官方直连 · 一个接口接入 Claude / GPT / Gemini · 7×24 稳定

免费注册试用 →