1. 7API
  2. Docs
  3. Prompt caching

Prompt caching

When a request starts with the same prefix as a recent one (the same system prompt, tools and earlier conversation turns), the upstream provider can read that prefix from cache instead of processing it again. 7API bills those cached input tokens at each model's cache rate, which is usually 70–95% below the standard rate. For coding agents, which resend a growing conversation on every turn, caching is the largest single factor in cost.

How it's billed

text
standard_tokens = new_input + cache_writes + output
cost_usd        = (standard_tokens × model_rate + cached_input × cache_rate) / 1,000,000
  • Cache writes are billed at the standard rate. There is no write surcharge.
  • Cached input is billed at the cache rate shown for each model on the pricing page.
  • Token counts are never rounded, and there is no per-request minimum.

Example: glm-5.3 costs $0.05 per million standard tokens and $0.01 per million cached tokens. A turn with 150,000 cached input tokens, 2,000 new input tokens and 800 output tokens costs (2,800 × 0.05 + 150,000 × 0.01) / 1,000,000 = $0.00164. Without caching, the same turn would cost $0.00764.

How to tell whether a request hit the cache

FormatField
Chat Completionsusage.prompt_tokens_details.cached_tokens, part of prompt_tokens
Responsesusage.input_tokens_details.cached_tokens
Anthropic Messagesusage.cache_read_input_tokens (not included in input_tokens) and usage.cache_creation_input_tokens

The dashboard's Usage page and GET /v1/usage show your cached share and the dollars saved for each period.

For eligible repeated input, 7API may fund cache-rate protection. Covered tokens are reported in these same cached-token fields and charged at the cache rate, even when the upstream processed them without a cache hit. These fields describe billable cache-rate usage; they are not proof of upstream cache reuse. New input and output remain subject to the model's standard rate.

Getting more cache hits

Caching is automatic on most models. The gateway passes Anthropic cache_control breakpoints through unchanged, so clients that set them, such as Claude Code, keep their behavior. What determines your hit rate is how stable your prompt prefix is:

  1. Keep the beginning of the prompt fixed. Put the system prompt, tool definitions and long reference documents first, and don't edit them between turns.
  2. Append, don't rewrite. Add new turns at the end. Changing an early message invalidates the cache from that point onward.
  3. Avoid per-request noise early in the prompt. Timestamps, random IDs or reordered tool lists near the top cause misses on every turn.
  4. Keep one conversation on one model. Caches are per model. Switching models mid-conversation starts cold.
  5. Expect a miss on the first request. The first request in a session writes the cache, and later ones read it.