persona: 1h prompt-cache TTL on BYOK narration blocks - #26
Open
shauntrennery wants to merge 1 commit into
Open
Conversation
Narration traffic is bursty: events often arrive >5m apart, so the ~11k-token cached system block expires and rewrites at 1.25x input price dozens of times a day. 9 days of BYOK usage data showed cache writes at 44% of total narration spend (3x the cache-read line). A 1h TTL writes at 2x but refreshes on every hit, so break-even is ~1.6 rewrites/hour; typical sessions sit well past that. Worst case (gaps >1h, both TTLs always cold) costs +0.8 cents per 11k block. Managed path untouched - heard-api sets cache_control server-side. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Narration traffic is bursty: events cluster while an agent is working, with gaps in between. Whenever a gap exceeds the default 5-minute cache TTL, the next event rewrites the ~11k-token cached system block at 1.25× input price.
Nine days of my own BYOK cost data (Anthropic console export, Haiku 4.5) shows how much that adds up:
input_cache_write_5minput_no_cacheinput_cache_readoutputAt Haiku rates that write line is ~340 rewrites of the block over 9 days (~38/day) — the cache spends most of the day expiring and rebuilding.
Change
Both BYOK
cache_controlblocks inpersona.py(harness path +_byok_haiku_rewrite) now use{"type": "ephemeral", "ttl": "1h"}. The managed path is untouched — heard-api sets itscache_controlserver-side, so mirroring this there is a separate (heard-api) decision.Math
Expected effect on the data above: the write line roughly halves (~20% off total narration spend). 1h TTL is GA — no beta header, works with the existing request shape.
Validation
ruffclean, 946 tests pass.cache_write=10630as the single 1h entry; happy to follow up with a before/afterhaiku_cachelog comparison after a few days of real use.🤖 Generated with Claude Code