Skip to main content
To save on inference costs, you can enable prompt caching on supported providers and models. Inworld Router supports both implicit and explicit caching.

Implicit Caching

Implicit caching depends on the model provider. If a provider supports prompt caching, it works automatically on their terms—no configuration required.
Provider stickiness: Inworld Router ensures all requests go to the same model provider for a given conversation. If you hit cache with one provider, subsequent requests stay routed to that provider, so you never lose cached data by being switched to a different provider.
Implicit caching is typically available on providers like OpenAI, DeepSeek, and Google Gemini 2.5. Each provider has its own minimum token requirements and TTL behavior. Consult the provider’s documentation for pricing and model-specific details.

Explicit Caching

Explicit caching is supported for Anthropic and Google providers. It gives you control over what gets cached and for how long.

Unified Protocol

Both providers use the same protocol: a cache_control object in each message content part, including a configurable ttl (time to live).

Cache Control in Messages

Add cache_control to text parts within multipart message content. Reserve it for large bodies of text such as character cards, CSV data, RAG context, or book chapters.

TTL Management

  • Configurable TTL: Set ttl in the cache_control object (e.g., "ttl": "5m", "ttl": "1h").
  • Update at any time: You can change the TTL on subsequent requests if you originally set it longer than needed.
  • Automatic prolongation: When 5% or less of the TTL remains and there are still messages hitting the cache, Inworld Router automatically extends the TTL to keep your cache warm.

User Message Example

Inspecting Cache Usage

To see how much caching saved on each generation, check the prompt_tokens_details object in the usage response.

Request and Response Samples

The following samples were verified against the Inworld Router API. The first request establishes a cache; the second request hits the cache. Request 1 — Cache write (establishing cache)
Response 1 — Cache write
Request 2 — Cache hit (same conversation, follow-up question) Send the same system message and cached content, plus the previous exchange and a new user message:
Response 2 — Cache hit
On the cache hit, cached_tokens is 1388 and cache_write_tokens is omitted (no write). The cached content is reused, reducing input token cost.
Explicit caching requires a minimum of 1024 tokens in the cacheable content block. Shorter content returns a validation error.

Response Example (summary)

Usage Fields

Some providers charge differently for cache writes vs. reads. Anthropic, for example, charges for cache writes but offers discounts on cache reads. Check provider pricing for details.