# Response Caching

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


# Response Caching

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](/features/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:

```typescript
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:

| Header | Value | Effect |
|---|---|---|
| `cf-aig-cache-ttl` | seconds, e.g. `600` | Cache this response for that long |
| `cf-aig-skip-cache` | `true` | Never cache this request |

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

```bash
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?" }]}'
```


## Related

- [Prompt Caching](/docs/features/caching.md)
- [Usage Explorer](/docs/features/usage-explorer.md)
