API reference
Prompt caching
Reuse provider-cached prompt prefixes to reduce latency and cost.
Session pinning requires a prompt cache key: Send a stable prompt_cache_key on every API request in a session so Router can prefer the provider that already has your prompt cached. Without this key or a supported client session ID, Router does not pin the session to a provider.
As the gateway between your application and your model provider, Router respects provider prompt caching. Router forwards your prompt cache directives to the model provider, translating them where the provider uses a different format, and you will be billed for cache reads and writes.
Providers differ in whether they cache your prompt by default:
- OpenAI models cache repeated prompt prefixes automatically. You don't need to do anything, although a prompt_cache_key still helps (see OpenAI models).
- Claude models only cache your prompt when the request says where to cache it. A Claude request with no caching instructions is never cached, so every request pays the full input price.
This table summarizes what turns caching on for each API:
Responses API | Messages API | |
|---|---|---|
OpenAI models | Automatic | Automatic |
Claude models | ||
If you aren't sure where to start, send a stable prompt_cache_key for each conversation. It turns on caching for Claude models on the Responses API, and it enables session pinning on eligible routes.
When you send a Claude model a Responses request, you can turn on caching in any of these ways:
- Send a prompt_cache_key. Router will mark cache breakpoints for you. This keeps both the stable prefix and the growing conversation cached from one turn to the next, and it is the simplest option for most applications.
- Mark breakpoints with prompt_cache_breakpoint. Add "prompt_cache_breakpoint": {"mode": "explicit"} to an input content part, and Router will translate it into a Claude cache breakpoint at that position, with Anthropic's default five-minute cache lifetime. This is the same field OpenAI uses for explicit breakpoints, so it's a good choice if the same request may be served by either provider.
- Mark breakpoints with cache_control. Add Anthropic's cache_control object to an input content part, a function tool, a function call or function call output item, or a message item itself, and Router will pass it to Claude. A marker on a message item lands on the last content block of that message, so the cached prefix ends with the whole message. Use this format when you need Anthropic-specific options, such as a one-hour cache lifetime with "ttl": "1h". See Anthropic's prompt caching guide for the available options.
For example, this request caches its long system prompt by marking the end of the developer message:
curl "https://api.router.com/v1/responses" \
-H "Authorization: Bearer $RAMP_ROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"input": [
{
"role": "developer",
"content": [
{
"type": "input_text",
"text": "<a long, stable system prompt>",
"prompt_cache_breakpoint": {"mode": "explicit"}
}
]
},
{"role": "user", "content": "Summarize the latest report."}
]
}'Keep these rules in mind when you choose between the options:
- Your own breakpoints take precedence. If a request carries any prompt_cache_breakpoint or cache_control marker, Router uses only your markers and doesn't add its own, even if you also send a prompt_cache_key. The key still enables session pinning on eligible routes.
- A marker that can't be placed returns an error. If you put a marker on a message that has no content to carry it, such as an empty message, or your markers conflict on the same block, Router will return a 501 instead of dropping the marker.
- Anthropic's top-level automatic cache_control works too. If you send "cache_control": {"type": "ephemeral"} at the top level of a Responses request, Router will pass it to Claude as automatic caching, exactly as on the Messages API, and will also mark your stable prefixes as described in Claude models on the Messages API. A prompt_cache_key gives you similar automatic caching with Anthropic's default five-minute cache lifetime; for a longer lifetime, use cache_control with a ttl.
- prompt_cache_retention applies only to OpenAI models. For a longer Claude cache lifetime, use cache_control with a ttl.
- Anthropic's own limits still apply, such as the maximum number of breakpoints in a request and the minimum prompt length that can be cached. See Anthropic's prompt caching guide for the current limits.
Note that cache_control is Anthropic's format. If a request that carries cache_control is served by a non-Claude model, for example after a fallback, Router doesn't translate it. Depending on the provider, Router either passes cache_control through unchanged, in which case the provider may reject the request, or leaves it out. For routes that mix Claude and other models, prefer prompt_cache_key or prompt_cache_breakpoint.
Router will pass through any explicit Anthropic cache_control values if the request is routed to an Anthropic model. Router does not otherwise modify caching values, with one exception: if you use Anthropic's top-level automatic cache_control and place no other markers, Router also caches your stable prefixes, such as your tools and system prompt, separately, so they stay cached as the conversation grows.
For non-Anthropic models, Router does not attempt to translate Anthropic cache_control values into native equivalents for the provider, and standard prompt-caching behavior for that provider applies instead.
OpenAI caches repeated prompt prefixes automatically. For GPT-5.6 and GPT-6 models, Router also helps keep the stable parts of your prompt cached as the conversation grows. Router doesn't do this if you place your own prompt_cache_breakpoint markers or set "prompt_cache_options": {"mode": "explicit"}.
On routes that use only OpenAI, if you ask for a longer cache lifetime, either with prompt_cache_retention: "24h" or with a ttl of 12h in prompt_cache_options or on your prompt_cache_breakpoint markers, Router keeps preferring the same provider for that longer period. See OpenAI's prompt caching guide for provider cache requirements and retention options.
Router may still fail over to another provider if the preferred provider becomes degraded.
Each response reports how many input tokens were read from or written to the cache:
- Responses API: usage.input_tokens_details.cached_tokens counts cache reads. For Claude models and OpenAI's GPT-5.6 and GPT-6 models, usage.input_tokens_details.cache_write_tokens counts cache writes. usage.input_tokens includes both.
- Messages API: Anthropic's usage.cache_read_input_tokens and usage.cache_creation_input_tokens count reads and writes, and usage.input_tokens excludes both.
Cache reads are much cheaper than regular input. For Claude models and OpenAI's GPT-5.6 and GPT-6 models, however, cache writes cost more than regular input, so caching a prompt you only send once can cost more than not caching it. Cache the parts of your prompt that you reuse, such as long system prompts, tool definitions, and earlier conversation turns. You can find each model's cache prices in router.pricing from GET /v1/models.
Reuse the same prompt_cache_key, for example "coding-session-123", for related requests, and use a different key for each new session. For eligible routes with multiple providers, Router will prefer the provider and service tier that successfully served the session's previous request. Supported coding-agent clients can also supply a session ID, which Router uses for pinning when a request has no prompt_cache_key.
This preference is not a permanent provider lock. Router keeps preferring the same provider for a short time after each successful request, roughly matching how long the provider keeps your prompt cached. After that, Router can select a provider again on the next request.
Provider degradation can override session pinning. Router may select a healthier alternative or fall back after a failure even while the session is pinned. Pinning helps reuse a warm cache; it does not prevent failover or guarantee a cache hit.
Before relying on prompt caching, check the model's router.capabilities.prompt_caching value from GET /v1/models to ensure that prompt caching is supported.
Provider caches are specific to a given provider and model. If Router must select a different provider for some later request (for instance, if a provider is degraded), the cache may need to be warmed on that provider, resulting in additional costs and higher latency for that request.
You may want to periodically keep the prompt cache warm, particularly if:
- You use fallback models and have a long prompt prefix, and want to optimize latency in the event of a fallback. You should evaluate whether the latency improvement justifies the cost of initiating "wasted" requests for your fallback models.
- You are waiting for a long (at least longer than the provider's cache TTL) tool call to complete, and sending a request to keep the cache warm would cost less than allowing the cache to expire. A typical example of this would be a coding agent using a frontier model.
When session pinning applies, Router will prefer forwarding requests to the provider that last served the session successfully, to help reuse its warm cache.
Router currently doesn't support caching responses on your behalf.