I've been building agent pipelines for a while, and the 30-second keepalive was one of those conventions I inherited and never questioned. It's in every template: parking a 100k-token system prompt in the provider's KV cache, then firing a cheap read every half-minute during pauses. Aider shipped it in 2024. Anthropic's docs recommend pre-warming. The interval got copied around so fast nobody asked whether it was right.
Then I read Maxim Khailo's empirical study (blog post, July 2026). He ran a measurement harness across four providers—Anthropic, OpenAI, Gemini, DeepSeek—recording exactly when caches die and what keepalives actually cost. The numbers changed how I think about my own agent infrastructure. This is what I learned and what I'm doing differently now.
Why I was wrong about the ping interval
The arithmetic is straightforward once you see it. I'd been paying for a ping every 30 seconds. That's $0.03 per ping on Anthropic with a 100k prefix at Sonnet 4.5 pricing ($0.30/M input, 0.1× cached-read multiplier). Fifteen pings in 7.5 minutes. The cold re-prefill I was trying to avoid costs $0.38.
So at a 10-minute pause, my keepalive was spending $0.45 to dodge a $0.38 cost. Every pause longer than 6 minutes on Anthropic, I was losing money on the insurance.
Khailo's data shows the right interval is about 4 minutes—TTL minus margin for Anthropic's 5-minute hard eviction. At that rate, the same 10-minute pause costs $0.06 in pings and saves $0.38. That's a 7.8× reduction in ping cost for the same warmth. His harness held 23 of 24 samples warm at 4-minute intervals with 0.1-second drift. The cache doesn't care whether you check in every 30 seconds or every 240.
The three cache regimes, and why they matter differently
The bigger surprise isn't the interval itself—community posts like Brandon Wie's worked that out on paper. What I hadn't internalized is that keepalive economics are per-provider, not universal. Khailo's measurements reveal three fundamentally different behaviors, and the right strategy flips depending on which one you're talking to.
Hard TTL (Anthropic). Eviction is a cliff. At 5 minutes you're warm; at 10 minutes you're dead—0 of 48 samples hit cache in the study. The keepalive holds 40 of 40. This is the only regime where you're buying real eviction prevention, not variance reduction. With Anthropic's 1.25× cache-write premium on re-prefill (making the thing you avoid expensive) and cheap 0.1× reads (making the premium small), the break-even horizon is about 46 minutes. Past that, stop pinging.
Sticky (OpenAI, Gemini). The baseline survives 10 minutes without help. OpenAI: 39 of 48 warm unaided. Gemini: 20 of 24. The keepalive removes variance, not the risk of eviction. At sub-10-minute gaps, you're paying premiums into a policy that was never going to pay out. Gemini makes it worse with 0.25× cached reads instead of 0.1×—your premiums are 2.5× more expensive before you even start.
Lossy (DeepSeek via DeepInfra). The keepalive itself misses about 20% of the time at a 1-minute gap. Router endpoint pins don't guarantee machine affinity—your ping warms cache on server A, your follow-up lands on server B. The cold re-prefill costs $0.043 for 100k tokens. The keepalive buys latency (TTFT drops from 5.4s to 1.4–2.0s), not money. That's a legitimate tradeoff for interactive use, but it's a different decision.
What this costs at scale
I ran the numbers for my own setup. A team running 100 agent sessions per day, each with one 10-minute pause per session (tool call, test run, approval wait), at Anthropic Sonnet 4.5:
- 30-second keepalive: 100 sessions × 20 pings × $0.03 = $60/day in ping costs. Still occasionally paying the $0.38 re-prefill when a session runs long.
- 4-minute keepalive: 100 sessions × 2.5 pings × $0.03 = $7.50/day. Same warmth.
- Adaptive (ping only during real idle, let die on long pauses): ~$5/day plus occasional cold re-prefills at $0.38 when the pause exceeds 46 minutes.
That's $18,000–$20,000/year in avoidable cost for a team that never questions the convention. At scale, the 8× isn't just a curiosity—it's real operating expense.
The adaptive keepalive pattern I now use
Khailo's pi agent harness implements what I think is the right pattern: pings only while a tool batch runs, default off. I've adapted that into a simple policy:
Set the interval to provider TTL minus margin. Anthropic's 5-minute TTL → 4 minutes. OpenAI's 5–10 minute window → 8 minutes. Never 30 seconds.
Know your provider's regime. The decision tree is simple: if the provider has hard TTL (Anthropic), keepalive saves money up to the break-even horizon (~46 min). If the cache is sticky (OpenAI, Gemini), skip it for sub-10-minute gaps. If re-prefill is cheap (DeepSeek), keepalive is a latency play—accept it or skip it accordingly.
Stop pinging past the break-even point. The formula: break-even idle ≈ τ × (w/r − 1), where τ is your interval, w is the re-prefill multiplier, and r is the cached-read multiplier. For Anthropic at 4-minute intervals: 4 × (1.25/0.1 − 1) ≈ 46 minutes. Every ping past that is burning money on a policy you'll never claim.
Never warm a dead session. Agents that go silent for hours shouldn't be pinging at all. The harness pattern—ping only during active tool execution—is the right default.
The other side of the cache: what CacheWise tells us
What I keep thinking about is that the keepalive is a client-side hack for a server-side problem. The CacheWise paper (Tiwari et al., presented at AgentSys 2026) studied KV-cache management from the serving side and found that naive eviction policies wreck the enormous prefixes agents reuse. Their trace analysis shows from the server's perspective exactly what Khailo measured from the client's: agent sessions are a fundamentally different workload than chatbot traffic, and the infrastructure isn't built for them yet.
Khailo flags an externality I hadn't considered: once every client adopts intelligent keepalives, the cache tier itself changes. A keepalive manufactures recency. Under LRU eviction, every client's rational rent payment (pinging to hold their slot) imposes an unpriced cost on every other tenant. The cache becomes a commons problem.
I think he's right that this pushes providers toward direct residency billing. Google's explicit cache already charges per token-hour held. Anthropic's 1-hour extended cache tier at 2× write price is a step in the same direction. The keepalive arbitrage is real today, and it has an expiry date.
What I changed
My agent harness now pings at 4 minutes, not 30 seconds. It knows which provider it's talking to and adjusts its policy accordingly—or disables keepalive entirely if the economics don't work. It stops pinging past 46 minutes on Anthropic. It uses the pi-style adaptive activation: pings only during active tool execution.
The 30-second keepalive was cargo-cult optimization. The numbers were there—I just hadn't looked. Khailo's study did the measuring so I didn't have to. All I had to do was read the data and change a config file.
All provider measurements and cache-retention data from Maxim Khailo's empirical study (2026-07-21). Provider pricing at Sonnet 4.5, GPT-5.1, DeepSeek V3.2, Gemini 2.5 Pro list rates as of the study date. CacheWise paper: Tiwari et al., arXiv:2606.16824, June 2026.