Choose which old messages to drop to hit a token target without touching the cached prompt prefix
Given a conversation, the index of the last message inside the provider's cached prefix, and a token target, returns which messages to drop: whole tool call plus tool result pairs (so no result is left without its call) and messages the caller marked droppable, oldest first or largest first, never inside the cached prefix, never the most recent keepRecent messages, never pinned ones. Everything up to the cache breakpoint stays byte-identical because it is never selected; the response carries a digest of that prefix so a later call can confirm it did not change. Does not summarize, edit or reorder messages, and does not know any provider's minimum cacheable size or TTL.
What you get
Shrinks a long agent transcript without busting the prompt cache. 500 messages per $0.005 call.
Call it
Send the JSON body below to https://agents.writerslogic.com/api/v1/conversation-prune. An unpaid request answers 402 with the price and how to pay; a request that fails with a 5xx status is not charged.
curl -i -X POST https://agents.writerslogic.com/api/v1/conversation-prune \
-H 'content-type: application/json' \
-d '{"messages":[{"role":"system","content":"You are a support agent.","tokens":400},{"role":"user","content":"Look up order 1042.","tokens":20},{"role":"assistant","kind":"tool_call","toolCallId":"t1","tokens":30},{"role":"user","kind":"tool_result","toolCallId":"t1","tokens":6000},{"role":"assistant","content":"Order 1042 shipped.","tokens":15},{"role":"user","content":"Thanks. Now order 1043.","tokens":20}],"cacheBreakpoint":1,"targetTokens":1000,"keepRecent":2}'
Input
| Field | Type | Required | Description |
|---|---|---|---|
messages | array<object>; max 500 items | yes | Up to 500; 400000 characters of content in total. |
cacheBreakpoint | integer; -1..499 | yes | Index of the last message inside the cached prefix; -1 when nothing is cached. |
targetTokens | integer; 0..100000000 | yes | Total tokens to get at or under. |
keepRecent | integer; 0..100 | no | Most recent messages that are never dropped. Default 4. |
strategy | string; one of "oldest-first", "largest-first" | no | Order in which droppable units are removed. Default oldest-first. |
tokenizer | string; length 0..64 | no | o200k_base or cl100k_base. Any other name (including Claude models) returns status unsupported for items that need counting; caller token counts are always accepted. |
Example request body
{
"messages": [
{
"role": "system",
"content": "You are a support agent.",
"tokens": 400
},
{
"role": "user",
"content": "Look up order 1042.",
"tokens": 20
},
{
"role": "assistant",
"kind": "tool_call",
"toolCallId": "t1",
"tokens": 30
},
{
"role": "user",
"kind": "tool_result",
"toolCallId": "t1",
"tokens": 6000
},
{
"role": "assistant",
"content": "Order 1042 shipped.",
"tokens": 15
},
{
"role": "user",
"content": "Thanks. Now order 1043.",
"tokens": 20
}
],
"cacheBreakpoint": 1,
"targetTokens": 1000,
"keepRecent": 2
}
Result
The response is { "data": ..., "_provenance": ... }. data carries these fields; _provenance is a signed W3C Verifiable Credential with a C2PA-style manifest, checked free at POST /api/v1/verify-provenance.
| Field | Type | Required | Description |
|---|---|---|---|
status | string; one of "pass", "fail", "unknown", "unsupported" | no | pass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass. |
keep | array<integer>; max 500 items | no | Indices of messages to keep, ascending. |
dropped | array<object>; max 500 items | no | |
tokensBefore | integer | no | |
tokensAfter | integer | no | |
targetMet | boolean | no | |
prefix | object | no | |
notes | array<string>; max 20 items | no | |
witnesses | array<object> | no | |
versions | object | no | Every semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile). |
limits | array<string> | no | |
deterministic | boolean | no | Always true: pure code, no model. |
Pay and connect
Available through: x402 (USDC on Base), MCP. MCP clients reach it through the context-evidence-kit package.
Machine-readable
- This agent as JSON (schemas, example, OpenAPI operation)
- Free signed sample response
- OpenAPI 3.1 · Catalog · Index of every agent