docs: document cacheRetention parameter (#6270)

* docs: document cacheRetention parameter (#6240)

* docs: standardize cacheRetention value quoting style

* style: format anthropic.md table

* Docs: align cacheRetention inline example

---------

Co-authored-by: Sebastian <sebslight@gmail.com>
This commit is contained in:
Kimitaka Watanabe
2026-02-01 23:16:37 +09:00
committed by GitHub
parent b897389b87
commit 7a8a39a141
3 changed files with 27 additions and 7 deletions

View File

@@ -15,13 +15,13 @@ Session pruning trims **old tool results** from the in-memory context right befo
- When `mode: "cache-ttl"` is enabled and the last Anthropic call for the session is older than `ttl`.
- Only affects the messages sent to the model for that request.
- Only active for Anthropic API calls (and OpenRouter Anthropic models).
- For best results, match `ttl` to your model `cacheControlTtl`.
- For best results, match `ttl` to your model `cacheRetention`.
- After a prune, the TTL window resets so subsequent requests keep cache until `ttl` expires again.
## Smart defaults (Anthropic)
- **OAuth or setup-token** profiles: enable `cache-ttl` pruning and set heartbeat to `1h`.
- **API key** profiles: enable `cache-ttl` pruning, set heartbeat to `30m`, and default `cacheControlTtl` to `1h` on Anthropic models.
- **API key** profiles: enable `cache-ttl` pruning, set heartbeat to `30m`, and default `cacheRetention: "short"` on Anthropic models.
- If you set any of these values explicitly, OpenClaw does **not** override them.
## What this improves (cost + cache behavior)

View File

@@ -37,10 +37,17 @@ openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
## Prompt caching (Anthropic API)
OpenClaw does **not** override Anthropics default cache TTL unless you set it.
This is **API-only**; subscription auth does not honor TTL settings.
OpenClaw supports Anthropic's prompt caching feature. This is **API-only**; subscription auth does not honor cache settings.
To set the TTL per model, use `cacheControlTtl` in the model `params`:
### Configuration
Use the `cacheRetention` parameter in your model config:
| Value | Cache Duration | Description |
| ------- | -------------- | ----------------------------------- |
| `none` | No caching | Disable prompt caching |
| `short` | 5 minutes | Default for API Key auth |
| `long` | 1 hour | Extended cache (requires beta flag) |
```json5
{
@@ -48,7 +55,7 @@ To set the TTL per model, use `cacheControlTtl` in the model `params`:
defaults: {
models: {
"anthropic/claude-opus-4-5": {
params: { cacheControlTtl: "5m" }, // or "1h"
params: { cacheRetention: "long" },
},
},
},
@@ -56,6 +63,19 @@ To set the TTL per model, use `cacheControlTtl` in the model `params`:
}
```
### Defaults
When using Anthropic API Key authentication, OpenClaw automatically applies `cacheRetention: "short"` (5-minute cache) for all Anthropic models. You can override this by explicitly setting `cacheRetention` in your config.
### Legacy parameter
The older `cacheControlTtl` parameter is still supported for backwards compatibility:
- `"5m"` maps to `short`
- `"1h"` maps to `long`
We recommend migrating to the new `cacheRetention` parameter.
OpenClaw includes the `extended-cache-ttl-2025-04-11` beta flag for Anthropic API
requests; keep it if you override provider headers (see [/gateway/configuration](/gateway/configuration)).

View File

@@ -97,7 +97,7 @@ agents:
models:
"anthropic/claude-opus-4-5":
params:
cacheControlTtl: "1h"
cacheRetention: "long"
heartbeat:
every: "55m"
```