Skip to Content
IDEsOpenRouterPrompt caching

OpenRouter prompt caching

OpenRouter prefix caching (and provider-side prompt caching) discounts input tokens when the start of your prompt matches a cached prefix. OpenRouter returns cache metrics on every response — no extra API flag required for basic accounting.

This page answers openrouter prefix caching, openrouter cache, and openrouter prompt caching.

Hub: Tokenminning with OpenRouter. Concept stack: Prompt caching.

Read cache metrics

Every response includes usage.prompt_tokens_details:

{ "usage": { "prompt_tokens": 10339, "completion_tokens": 60, "prompt_tokens_details": { "cached_tokens": 10318, "cache_write_tokens": 0 } } }
FieldMeaning
cached_tokensTokens read from cache — >0 means cache hit
cache_write_tokensTokens written on first request establishing cache
cache_discountCost effect of cache (response body when present)

Also visible on Activity detail rows and GET /api/v1/generation.

Why cached_tokens stays zero

CauseFix
Prompt too short for provider minimumLonger stable prefix (system + tools)
System prompt changes every turnStabilize AGENTS.md, rules, MCP schemas
Cache expiredProvider TTL; resend same prefix
Provider drift between turnsSet stable session_id for sticky routing
Client reshuffles message orderStatic system block first, dynamic user content last

Stabilize the prefix

  1. Static first — system prompt, tool definitions, stable rules
  2. Dynamic last — user messages, retrieved chunks, run-specific state
  3. Do not edit the system block every agent turn in IDE clients

OpenCode/Cursor/Devin MCP and rules bloat hurts caching as much as raw tokens — trim MCP before chasing cache flags.

Explicit caching (Anthropic and others)

Some providers need cache_control on content blocks. OpenRouter supports:

  • Automatic top-level cache_control — advances breakpoint as conversation grows (Anthropic direct routing)
  • Explicit per-block breakpoints — fine-grained control (max four breakpoints)

See OpenRouter prompt caching guide .

For multi-turn agent work, set a stable session_id so routing stays on a provider that retains your cache.

Agent workflow checklist

  1. Pin system prompt + tool schemas across turns in the session
  2. Set session_id per conversation or workflow
  3. Inspect cached_tokens after turn 3+ — should climb in stable chats
  4. Compare cost in Activity before/after stabilizing rules

vs semantic caching

LayerMatchesOpenRouter field
Prefix / prompt cachingExact prefix reusecached_tokens
Semantic cachingSimilar meaningSeparate app layer — Semantic caching
Last updated on