The Messages API is stateless: each turn of a conversation re-sends everything the model should remember. A 30-turn support chat or a long agentic coding session can accumulate tens or hundreds of thousands of tokens of history, all billed as input on every subsequent turn. The instinctive fix is to summarize old history into a short digest. Sometimes that's right. But two platform facts complicate the instinct, and they cut in opposite directions.
Two facts that reshape the math
Fact one: long context carries no premium. Claude Fable 5, Opus 4.8, Sonnet 5, and the other 1M-context models bill a 900k-token request at the same per-token rate as a 9k-token one, with the full 1M window on by default. You won't hit a pricing cliff by carrying history — cost grows linearly, and quality-wise the model keeps verbatim access to every earlier detail.
Fact two: cached history costs a tenth. Conversation history is a textbook prompt-caching workload — each turn's prompt is the previous turn's prompt plus a little more, a perfect prefix. Cached input reads bill at 0.1x the base input price. On Claude Opus 4.8, carrying 100,000 tokens of cached history costs 100,000 × $0.50/1M = $0.05 per turn instead of $0.50 uncached. Summarizing that history down to 5,000 fresh tokens costs 5,000 × $5/1M = $0.025 — plus the output cost of generating the summary itself, and here's the trap: rewriting history changes the prompt prefix, invalidating the cache and forcing a re-write at 1.25x. Naive summarization can cost more than the verbatim history it replaced.
When compression genuinely wins
You're running out of window. At 200k (Claude Haiku 4.5) or even 1M tokens, agentic sessions with large tool results eventually overflow — input alone exceeding the window is a hard 400 error. Compression stops being an optimization and becomes survival.
The old history is genuinely low-value. Fifty turns of "did that work?" / "yes" carry little the model needs verbatim. Tool results are the classic case: a 30,000-token search result matters intensely for one turn and almost never afterward.
Sessions outlive cache TTLs. A conversation resumed hours later pays full input price on the whole history anyway; resuming from a compact summary is straightforwardly cheaper.
The managed middle ground: compaction and context editing
You don't have to build summarization yourself. Two server-side mechanisms (both beta, both on the Claude API) automate the strategy:
Server-side compaction has Claude summarize older conversation content as the context fills: you enable a compact_20260112 edit with a token trigger (default 150,000, minimum 50,000), and the response includes a compaction block; append it and the API automatically drops everything before it on the next request. Supported on Fable 5, Opus 4.8/4.7/4.6, Sonnet 5, and Sonnet 4.6. Billing note: compaction iterations are billed separately and reported in usage.iterations — the top-level token counts don't include them, so sum all iterations for true cost. Put cache_control on compaction blocks and cache the system prompt separately so a new compaction doesn't torch your whole cache.
Context editing takes the surgical route: the clear_tool_uses_20250919 strategy strips old tool results server-side once input crosses a trigger (default 100,000 tokens), keeping the most recent few. Your client keeps its full history; the trimming happens before the prompt reaches the model. Clearing invalidates cache at the clearing point, so the docs recommend clear_at_least to make each invalidation clear enough tokens to be worth it.
To evaluate any of this before committing, the free count_tokens endpoint reports both the post-edit token count and context_management.original_input_tokens — a before/after for your compression strategy with real numbers.
Deciding per use case
Short interactive chats: full history plus 5-minute caching; don't bother compressing. Long agentic sessions with heavy tool use: full recent history plus context editing for stale tool results. Very long-lived assistants: compaction (or your own summary) at a threshold, with cache breakpoints placed to survive it. High-volume, latency-tolerant pipelines: pair whichever you choose with the batch discount and 1-hour caching. Measure quality before and after on your own evals — compression failures are silent, showing up as the model "forgetting" commitments made forty turns ago.
Where to go next
The economics here lean on the cache break-even math; the billing mechanics are in the token bill anatomy.