Skip to content

feat(app): default Anthropic prompt-cache TTL to 1h - #2102

Merged
aponcedeleonch merged 2 commits into
mainfrom
feat/anthropic-cache-ttl-1h-default
Oct 5, 2026
Merged

aponcedeleonch merged 2 commits into
mainfrom
feat/anthropic-cache-ttl-1h-default

Conversation

@aponcedeleonch

@aponcedeleonch aponcedeleonch commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Anthropic prompt-cache entries now default to the longest lifetime the API accepts, 1h, instead of the API default of 5m. Sessions with gaps longer than 5 minutes between requests no longer lose their cached prefix.
  • The built-in Anthropic Messages providers — anthropic, openrouter-anthropic and toolhive-anthropic — get the TTL from one rule, anthropicCacheTTLFor in internal/app/promptcache.go, so they cannot diverge. The rule depends on the provider ID only, so a base-URL override does not change it.
  • The existing --anthropic-cache-ttl flag is the knob for going back: --anthropic-cache-ttl=5m restores the shorter, cheaper-to-write lifetime. An operator value applies to every Anthropic Messages provider, as before.
  • Custom anthropic-messages providers keep the API default unless the flag is set, because an unknown compatible endpoint may reject ttl.
  • --no-prompt-cache still emits no ttl, so it keeps reproducing the pre-ADR-0100 wire byte-for-byte.
  • OpenAI needs no change. Pre-GPT-5.6 models already receive prompt_cache_retention: "24h" (provider/openai/cache.go), and GPT-5.6+ accept only the 30m TTL, which is their default. OpenRouter's Responses surface cannot express a TTL.

Provider documentation checked:

  • Anthropic prompt caching: ttl is 5m (default) or 1h. The 1-hour TTL is generally available and needs only the ttl field, with no anthropic-beta header. 1h writes cost 2× base input, against 1.25× for 5m; reads cost the same.
  • OpenRouter prompt caching: the Anthropic Messages surface supports "ttl": "1h".
  • OpenAI prompt caching: 24h retention before GPT-5.6; 30m is the only value from GPT-5.6 on.

Development stage

  • Plan / Interface — Bounded/Architectural behavioral and exact-interface contract; no implementation
  • Implementation — based on an approved, merged Plan / Interface PR
  • Combined — compact one-task Bounded/Architectural exception; no separate plan PR,
    and the in-PR plan declares **Expected tasks:** 1, a non-placeholder
    **Combined rationale:**, and no runtime/public/operator/persistence/trust-boundary
    interface change (None — rationale; workflow-only meta-changes may review process
    docs/skills here)
  • Spike / Routine / Cleanup — acceptance-plan spine exempt; Spike evidence does not ship as-is

Contract linkage

  • Work classification: Routine (operator-directed), pending reviewer confirmation
  • Classification rationale: Changes the default value of an existing operator flag. No new flag, config key, API or persistence change, and it is reversible with --anthropic-cache-ttl=5m. However, ADR 0100 records "default = API default" for this TTL and the default changes cost behavior, so a reviewer may classify it Bounded/Architectural. See the reviewer notes.
  • Decision record: None yet. ADR 0100 is not edited because frozen decisions are not rewritten in place. A superseding ADR can follow if reviewers want one.
  • Human waiver of spine: To be confirmed by the reviewing human
  • Acceptance plan: N/A
  • Human decisions resolved and recorded: N/A — the directing human chose a 1h default for anthropic, openrouter-anthropic and toolhive-anthropic, with one shared rule
  • Plan / Interface PR: N/A
  • Approved commit baseline: N/A
  • Combined/exemption rationale: See classification rationale

Interface conformance

  • No interface change. --anthropic-cache-ttl keeps its accepted values (5m, 1h); only the meaning of the unset value changes for the three built-in Anthropic Messages providers.

Issue relationship

None.

Type of change

  • Behavioral/interface plan
  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation/process
  • Other (describe):

Test plan

Baseline checks

  • Acceptance-plan checker
  • Linting (task lint) — timed out locally at 10 minutes; relying on CI. go vet and gofmt are clean on the touched packages.
  • Fast offline test suite (task test) — not run in full. The prompt-cache, ToolHive and OpenRouter-Anthropic tests in internal/app pass. Three other internal/app failures reproduce identically with this change stashed (TestYoloRelativeEscapeTools, TestYoloRelativeEscapeAuthorityUsesPhysicalTarget, TestCanonicalConfiguredDir_AllowsMissingDefaultParents), as do two cmd/mecatui exit-handoff tests that fail because the worktree path is too long for a Unix socket.
  • Pre-review race suite (task test:race) — not run locally
  • Offline demo (go run ./cmd/mecademo)
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build) — not run locally
  • Guarded engine API affected: compatibility check (task api:check) — N/A, no engine change
  • Intentional engine API change: task api:update + engine/CHANGELOG.md — N/A
  • Landed plan: strict acceptance trace (task ac-trace-strict) — N/A
  • Final implementation review: /panel-review

New and updated tests:

  • TestAnthropicCacheTTLDefault: runs identical cases against all three built-in providers (unset → 1h, operator 5m/1h wins, --no-prompt-cache → no ttl), and checks that custom providers keep the API default.
  • TestAnthropicCacheTTLDefaultsToOneHourOnBuiltinProviders: builds each real provider against a local server and checks that every cache_control marker in the body carries 1h (unset) or 5m (flag).
  • TestADR_0346_AnthropicCacheTTLStampedOnOpenRouterAnthropic: now expects 1h when the flag is unset.

A temporary wire capture (not committed) confirmed that all three providers send POST /v1/messages with anthropic-version: 2023-06-01, no anthropic-beta header, and {"type":"ephemeral","ttl":"1h"} on every marker.

Changes

File Change
internal/app/promptcache.go New anthropicCacheTTLFor: the one shared TTL rule
internal/app/registry.go Anthropic entry construction uses it
internal/app/build.go AnthropicCacheTTL doc comment
internal/app/promptcache_test.go, promptcache_breakpoint_e2e_test.go Tests listed above
cmd/mecated/main.go, cmd/mecak8s/flags.go, cmd/mecatui/config.go Flag help text
user-docs/building/what-you-get/observability.md Default value in the flag table
user-docs/building/deployment/mecated.md, user-docs/features/choose-models.md Default value

User-facing change

With --anthropic-cache-ttl unset, sessions on anthropic, openrouter-anthropic and toolhive-anthropic now cache prompts for 1 hour instead of 5 minutes. Cache writes cost 2× base input instead of 1.25×; reads are unchanged. Set --anthropic-cache-ttl=5m for the previous behavior.

Special notes for reviewers

  • Process classification: ADR 0100 says that at the default TTL the ttl field is omitted. This PR changes that default for the built-in providers. Please decide whether this needs a superseding ADR (Bounded/Architectural) or whether Routine is acceptable.
  • Cost: a 1h write costs 2× base input against 1.25× for 5m. It pays off when requests in a session are more than 5 minutes apart, and costs more for sessions with rapid, continuous turns.
  • Gating: the rule depends on the provider ID only, so anthropic and openrouter-anthropic with an overridden base URL now also send 1h. This matches toolhive-anthropic, whose base URL is always derived. Custom anthropic-messages providers are excluded.

The built-in Anthropic Messages providers (anthropic,
openrouter-anthropic, toolhive-anthropic) now share one rule in
anthropicCacheTTLFor: with --anthropic-cache-ttl unset they stamp
"ttl":"1h" on every cache_control marker, the longest lifetime
Anthropic accepts. --anthropic-cache-ttl=5m restores the shorter,
cheaper-to-write lifetime. Custom anthropic-messages providers keep the
API default unless the flag is set, and --no-prompt-cache still emits
no ttl so it reproduces the pre-ADR-0100 wire.

OpenAI needs no change: pre-GPT-5.6 models already receive
prompt_cache_retention=24h, and GPT-5.6+ accept only the 30m TTL, which
is their default.

Co-authored-by: Mecatl <[email protected]>
The flag table already states the default.

Co-authored-by: Mecatl <[email protected]>
@aponcedeleonch
aponcedeleonch merged commit 6b12806 into main Oct 5, 2026
39 checks passed
@aponcedeleonch
aponcedeleonch deleted the feat/anthropic-cache-ttl-1h-default branch October 5, 2026 12:53
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 7, 2026
2 tasks

This branch was successfully deployed

1 active deployment
Preview — 09658726 Deployed Oct 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants