Coding agents spend a lot of their time waiting: on builds, test suites, deployments, background jobs. Every wait longer than five minutes quietly throws away the provider's prompt cache, and the agent's next request pays to write the whole conversation again. OptScale AI Gateway can now keep that cache alive through the wait, and shows you whether doing so paid off.
The five-minute problem
Prompt caching is what makes long agent conversations affordable. Each request re-sends the full conversation, but the provider has already processed most of it, so that part is billed as a cache read at a fraction of the normal input price.
The catch is the cache's lifetime, or TTL. Anthropic keeps a cache entry for five minutes from its last read. A chat with a person rarely notices. An agent does: it hands a ten-minute build to its shell and sends nothing until the build finishes. Five minutes in, the entry lapses. When the tool result finally goes back to the model, nothing is cached, and the entire conversation is written to the cache from scratch.
The price difference is large. Relative to a model's base input price:
These are Anthropic's published multipliers. At the standard rate, a rewrite costs 12.5 times what a read would have, for exactly the same tokens. On Opus 5.5 and Sonnet 5.5, it costs 25 times. On Claude Sonnet 4.6, priced at $3 per million input tokens, a 100,000-token conversation costs about $0.03 to read and about $0.375 to rewrite. An agent that pauses dozens of times a day does this over and over, and the longer the conversation, the more each pause costs.
Keep-warm: a one-token ping that resets the clock
With keep-warm switched on, the gateway watches for waits and bridges them:
1. A response ends in a tool call. The gateway knows the client is now busy running something, and starts a timer for that conversation.
2. Every 4.5 minutes, it sends a refresh. The refresh is the exact prompt that was just sent, to the same endpoint with the same credential, with only two changes: max_tokens is set to 1 and streaming is turned off. The provider reads the prompt from cache, which resets the five-minute clock.
3. The agent returns. Its next request reads the conversation from cache, as if the pause never happened. The gateway cancels the schedule at once.
Why 1 rather than 0? Anthropic now also accepts max_tokens: 0 for pre-warming, but rejects it on requests with extended thinking, structured outputs or a forced tool choice, which are common in agent traffic. A ping changes nothing else in the request, so the gateway uses 1, which every pinged request accepts.
In the example above, a ten-minute build needs two pings at roughly $0.03 each. The return then reads the cache instead of rewriting it: about $0.06 spent to avoid about $0.345 of extra cost.
We first built this mechanism into the open-source OptScale Kompressor and measured it on Claude Code with Opus 5.5. There, keep-warm alone took about 11% off the Anthropic API bill after paying for its own pings. The gateway now does the same for every client that reaches Anthropic through it, with nothing to install on the client side.
Keep-warm also covers waits that do not end in a tool call. If a turn finishes while a background command, a monitor task or a scheduled wake-up is still outstanding, the gateway keeps the cache warm until the client reports the task done, stopped or canceled, or until the ping cap is reached. For a scheduled wake-up, it sends only as many pings as the reported delay needs.
Bounded by design
A refresh is a real, billed request, so the feature is built to stop early rather than run on:
• A hard cap. At most 11 pings per wait by default. They span about 50 minutes, and the last one keeps the cache warm for about 54. At Anthropic's standard price ratios, one avoided rewrite pays for roughly eleven pings of the same prompt, which is about where the default cap sits. On Opus 5.5 and Sonnet 5.5, where reads cost half as much, it pays for about twenty-four. For shell commands the cap is tighter still: it covers the command's timeout and no more, so a two-minute command gets a single ping.
• It stops when there is nothing left to save. A schedule ends on the next real request, on a failed refresh, or the moment a ping reads nothing from the cache.
• It only starts when there is something to keep. Prompts below 1,024 tokens, responses that neither read nor wrote the cache, requests with a fixed thinking budget, and conversations already on one-hour entries are never pinged.
• No side effects. A refresh does not execute gateway tools, rerun compression, retry or fall back to another provider. Requests that use remote MCP servers or provider-defined tools are excluded altogether.
• Same governance as everything else. Each refresh revalidates the provider key and passes the gateway's governance checks before sending.
Per-thread schedules. A main agent, its subagents and small side calls share a conversation but use different system prompts. Each gets its own schedule, so a long subagent run does not let the main prompt expire.


