Response Caching

Identical requests can be served from cache with no upstream call and no charge; automatic for deterministic calls, controllable per request.

When a request is byte-for-byte identical to one answered recently, AnyRouter returns the cached response with no upstream call and no charge. This differs from Prompt Caching, which still runs inference. Any change to messages, temperature or another field makes a request distinct.

It helps for deterministic requests (temperature: 0), embeddings, repeated identical prompts such as health checks and demos, and development loops around a fixed prompt.

Default

Deterministic chat/completions requests (temperature: 0 or unset), embeddings and speech requests are cached for about 5 minutes. Caching is never applied to zero-data-retention (ZDR) workspaces or to requests that opt out.

Control it

With the SDK:

import { AnyRouter } from "@anyr/sdk"

const client = new AnyRouter()

// Cache this exact response for 10 minutes.
await client.chat.completions.create(
  { model: "z-ai/glm-4.7-flash", messages: [{ role: "user", content: "What is the capital of France?" }] },
  { cacheTtl: 600 },
)

// Force a fresh upstream call.
await client.chat.completions.create(
  { model: "z-ai/glm-4.7-flash", messages: [{ role: "user", content: "Latest news?" }] },
  { skipCache: true },
)

With @anyr/ai-sdk-provider, pass the same options as providerOptions: { anyrouter: { cacheTtl: 600 } }.

With raw headers on any HTTP client:

HeaderValueEffect
cf-aig-cache-ttlseconds, e.g. 600Cache this response for that long
cf-aig-skip-cachetrueNever cache this request

cf-aig-cache-ttl accepts 60 seconds to 1 month (2,678,400 seconds); values outside are clamped.

curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer $ANYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "cf-aig-cache-ttl: 600" \
  -d '{"model": "z-ai/glm-4.7-flash", "messages": [{ "role": "user", "content": "What is the capital of France?" }]}'

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer