Track context compaction as part of the cost of a customer conversation. Include any extra model work for the compaction step and measure how much later turns save. The number of turns that follow compaction matters as much as the number of tokens you remove. If the user leaves after the next turn, a smaller context can still cost more overall.
Record the work where it occurs
Give each conversation an application ID and associate it with a customer when your server starts it. Record provider request IDs, the model and the provider account with each attempt. For compaction, record the point in the conversation, whether it occurred inside a normal response or in a separate request, and the source of the observed usage. This lets you link later savings to the policy that produced them.
OpenAI documents automatic compaction inside Responses and a standalone compaction endpoint. With standalone compaction, account for the extra request under the same conversation ID. With automatic compaction, tie the compaction marker to the response you received and use the documented usage for the path you run. Avoid adding a second estimated charge to a response total unless the provider documents a separate billable quantity. OpenAI compaction guide
For Claude threshold compaction, the top-level input and output counts omit the compaction iterations. When the response contains the iteration breakdown, use the iterations to account for billable sampling, including compaction. A later request that carries a previous compaction block can incur input usage for that request. Receiving the same block again is a poor proxy for a new compaction charge. Claude threshold compaction guide
Calculate the break-even turn
Suppose a SaaS support workspace pays an incremental $0.048 to compact a conversation. In this hypothetical example, each following turn costs $0.019 with the full context and $0.011 after compaction. The two per-turn amounts include the same expected output charge. They also account for whatever part of the input normally gets the cached rate.
| Following turns | Keep the full history | Compact once | Difference from compacting |
|---|---|---|---|
| 2 | $0.038 | $0.070 | $0.032 more |
| 6 | $0.114 | $0.114 | Equal |
| 10 | $0.190 | $0.158 | $0.032 less |
At $0.008 saved per following turn, six turns recover the initial cost and the seventh starts saving money. This estimate assumes the same per-turn prices and answer quality. In a replay, use each turn's actual cache reads and writes, output usage, and repeated compactions. If your uncompacted history would mostly be read at a discounted rate, use that rate for the comparison. See tracking prompt cache costs.
Start by comparing conversations with similar lengths and task types. Review whether compacted conversations still preserve items such as an unresolved customer approval or the current account record. A missed instruction can generate an additional model call or a manual correction. Capture those outcomes with cost and latency so you can decide which workloads justify a lower trigger.
Reconcile the estimate before changing a budget
Sum the request ledger by provider account, billing period and currency. Compare it with the provider's export at the finest dimensions both records support. A billing export that groups activity by project may confirm the total for a shared project. Your application ledger supplies the customer attribution. Leave differences in an unallocated bucket while you check for missing iteration fields, duplicate event deliveries, cache pricing and late usage. Treat disconnected requests with unknown usage as pending until you have evidence for the amount.
Alectura supports per-organization and per-user spend policies. If you route a compaction-capable workflow through the gateway, compare the amount recorded against provider usage before relying on it for that workflow's budget. Use a non-sensitive feature tag to identify the test cohort and keep conversation content out of tag values. Review Alectura spend limits.
Source documents (2)
- OpenAI compaction guideChecked
- Claude threshold compaction guideChecked
Trace a request through Alectura.
Bring a sample prompt and a customer policy. See what reaches the model and which decisions appear in the request record.