Need help?
<- Back

Comments (107)

  • Wowfunhappy
    I find it really weird that Anthropic uses only a five minute cache on the API. Even in the course of active work, many commands—compiling, running tests, etc—take longer than five minutes to complete.I of course don't know what it costs Anthropic to keep the cache warm—but since their subscription plans use one hour, Anthropic must have concluded a longer cache is more economical for most users. And there's a big difference between one hour and five minutes.
  • Aurornis
    On a subscription plan (not API requests) Claude Code defaults to 1-hour cache duration for the main conversation and 5 minutes for subagents.So if you're not paying API rates, you need not worry. You can force the main conversation or subagents to either 5 minute or 1 hour in the Claude settings file if you would like.If you are paying API rates, paying close attention to caching is important. 1 hour is best for sessions where you have to think a lot, examine output, or wait for long builds because 5 minute interruptions are very common. The price premium for 1-hour TTL isn't that high over 5-minute, so I use it by default.It's also good to get in the habit of doing /compact when you know you might be AFK for more than the cache TTL. Doing the /compact on a long context conversation after the cache has expired is much more expensive.
  • compiler-guy
    Everything old is new again. Something similar was a time honored technique for getting an OS scheduler to keep a long-running task at interactive priority by writing a character to the console every so often, so it looked like an interactive process.How to defeat these countermeasures used to be covered in os courses. I suspect the llm vendors will adopt similar techniques.https://algomaster.io/learn/operating-systems/multilevel-que...
  • whatifitoldyou
    Is there a pi plugin for resetting the keepalive? Sounds simple enough. From the article:What is a keep-alive ping for prompt caching? - You send the last request again with max_tokens set to 0 about every 4.5 minutes. The API reads the cached prefix, returns no output tokens and restarts the cache timer. In our replay, keep-alive pings capped by session depth cut a Claude coding bill by about 8 to 9% net.
  • jonenst
    What about using anthropic (or openai) models from other tools? E.g. github copilot or jetbrains junie ?
  • prathamgrv
    sure, but the other big use is chat with real users, and people are slower than agents. They don't answer within 5 minutes if they're actually working on something.
  • 8cvor6j844qw_d6
    If I'm not mistaken, on subscription plans your main agent defaults to 1 hour cache with subagents spawned by the main session on 5 minute cache timer.Best ensure your subagents avoid getting blocked if there's any wait or command that takes more than 5 minute.
  • bensyverson
    Isn't Claude Code on a 1hr cache?
  • extr
    This is obvious if you just put cache timeout in your statusline. If the nature of your work is such that every time you return to the window the 5m cache is expired, bump it up.
  • theanonymousone
    Where can I find cache "duration" of different providers? I have never seen such information, despite it being a very big deal in cost estimation. Or maybe it's dynamic?
  • rishabhaiover
    This is a big contributor to long-running sessions. I built a small CLI that opens in a tmux popup and shows what my Cursor agents cost: https://github.com/rishabhBudhouliya/tend.It uses a ridgeline chart to show how big each chat's context has grown and what it's spending.
  • larodi
    I've felt this long before and my agent's contexts are compacted very very often. Even though they work on a common bus, I try to keep them regularly pooled back to minimum.
  • superjan
    What helps: run agents in a VM so they can have full control and don’t need to wait for your approval. Firewall it from your local network.And start a new blank session with its own branch (and have the agent update the project readme) so you can restart without context.
  • refulgentis
    These AI written articles are exhaustingly long, and the #s included make it feel very scientific but are one offs for one person.It's self-labelled as a 15m read and a human in the loop should recognize it's about 3m, tops. Here:LLM API context caches, by default, only last for 5 minutes on Anthropic and 30m on OpenAI.If you use Claude, there's an hour cache for 2x the cost of the 5 minute one.If you use OpenAI, there's a 12 hour cache for 2.5x the cost of the 30m one.FWIW, it's very Chicken Little / "the sky is falling!!111!": the idea is if you walked away for > 5m between every Claude request, re-caching would be 23% of your bill.
  • NooneAtAll5
    just use deepseek10-100x cheaper is not something to sneeze at
  • antiloper
  • julianlam
    Requisite smarmy comment about how this is not an issue with local models.There's even the ability to persist your kv cache to disk, so future session resumptions load back into context instantly without needing to do a full prefill ingestion by the LLM. (CachyLLaMA, iirc, not sure where the project is now)
  • vikramkr
    Neon really cooked with tamping down on the inane incomprehensible Claude slop huh? It's so damn annoying when they spew this poetic babbling gibberish.TDLR prompts are cached. Prompt cache hit == $. Cache miss == $$$$$$$. Claude ttl is 5 min. Codex ttl is 30 min. If u take longer than 5 min between turns then $$$$
  • edwinarbus
    Edwin from Anthropic here. Thanks for the thorough writeup. I will point out two things:1. This looks like API-billed traffic only. Claude Code defaults to a 1 hour cache, not 5 min! So if you're within your plan's usage, this doesn't really apply [1].2. In the API, we have 5 min and 1 hour TTL options. The "23%" here for the 5 min option includes breaks over 30 min, where both Claude's and GPT's default caches have expired and the loss is the ~same (7.8% vs. 8.5%). If you run long sessions with breaks, and are using an API key, you could set "ttl": "1h". There will be a bit higher write price, though [2].[1] https://code.claude.com/docs/en/prompt-caching[2] https://platform.claude.com/docs/en/build-with-claude/prompt...
  • j45
    It feels a little click baity to not include the word API in that title somewhere.
  • the_mitsuhiko
    That's why pi has cache warming.
  • h1fra
    so we need this loop to keepalive?for +i; send prompt=prompt+"."
  • brunoborges
    Rust developers be like: "seriously?"
  • hoechst
    indecipherable slop article
  • triangulumlabs
    [dead]
  • ben-greenspring
    [dead]
  • ahaliav
    [dead]
  • oiwdis
    [dead]
  • zurfyx
    [dead]
  • cobwebcheck
    [dead]
  • k_ivanow
    [dead]
  • doctorpangloss
    This is so dumb. Sign the cache and ship it to the client, accept signed caches from clients, problem solved.