# Prompt Caching

> Cache long prompt prefixes across requests to cut cost and latency.


# Prompt Caching

Cache a long, repeated prompt prefix (system prompt, RAG documents, tool catalog, few-shot examples) so repeat requests pay a fraction of the input price. AnyRouter passes caching through on every upstream that supports it (Anthropic, OpenAI, DeepSeek, Gemini). If a chunk repeats in two or more requests within five minutes, cache it.

## Anthropic

Mark blocks with `cache_control`. Cache reads cost 10% of the input price, writes 125%, and the TTL is 5 minutes.

```typescript
const response = await client.messages.create({
  model: "anthropic/claude-sonnet-4-6",
  max_tokens: 1024,
  system: [
    {
      type: "text",
      text: LONG_SYSTEM_PROMPT,
      cache_control: { type: "ephemeral" },
    },
  ],
  messages: [{ role: "user", content: "What's the policy on refunds?" }],
})
```

## OpenAI

Prompts of 1024 tokens or more are cached automatically. No request change is needed.

## Check the result

Cached tokens appear in `usage`, and are billed at the provider's cache-read rate with no AnyRouter markup. Each [model page](https://anyrouter.dev/models) shows standard and cache-read prices.

```json
{
  "usage": {
    "prompt_tokens": 5840,
    "completion_tokens": 120,
    "total_tokens": 5960,
    "prompt_tokens_details": {
      "cached_tokens": 5800
    }
  }
}
```


## Related

- [Usage Explorer](/docs/features/usage-explorer.md)
- [Request Logs](/docs/features/request-logs.md)
- [Response Caching](/docs/features/response-caching.md)
