Choose which old messages to drop to hit a token target without touching the cached prompt prefix

$0.005 USDC per call · Agent infrastructure · POST /api/v1/conversation-prune · Id conversation-prune

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

FieldTypeRequiredDescription
messagesarray<object>; max 500 itemsyesUp to 500; 400000 characters of content in total.
cacheBreakpointinteger; -1..499yesIndex of the last message inside the cached prefix; -1 when nothing is cached.
targetTokensinteger; 0..100000000yesTotal tokens to get at or under.
keepRecentinteger; 0..100noMost recent messages that are never dropped. Default 4.
strategystring; one of "oldest-first", "largest-first"noOrder in which droppable units are removed. Default oldest-first.
tokenizerstring; length 0..64noo200k_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.

FieldTypeRequiredDescription
statusstring; one of "pass", "fail", "unknown", "unsupported"nopass: 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.
keeparray<integer>; max 500 itemsnoIndices of messages to keep, ascending.
droppedarray<object>; max 500 itemsno
tokensBeforeintegerno
tokensAfterintegerno
targetMetbooleanno
prefixobjectno
notesarray<string>; max 20 itemsno
witnessesarray<object>no
versionsobjectnoEvery semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile).
limitsarray<string>no
deterministicbooleannoAlways 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