Pick context blocks that fit a token budget, keeping mandatory blocks and their dependencies

$0.005 USDC per call · Agent infrastructure · POST /api/v1/context-pack · Id context-pack

Chooses which context items an agent should put into a prompt without exceeding a token budget: every mandatory item and everything it depends on is always included, then optional items by descending priority (each with the dependencies it pulls in) while they fit. Token counts come from the caller or from o200k_base / cl100k_base; any other tokenizer name returns unsupported (there is no Claude tokenizer, so nothing is estimated). Greedy by priority, not an optimal knapsack; per-item counts are summed and do not model merges across item boundaries (use perItemOverhead for separators). Does not summarize or rewrite items.

What you get

Stops context overflow and dropped dependencies before the model call. 500 items per $0.005 call.

Call it

Send the JSON body below to https://agents.writerslogic.com/api/v1/context-pack. 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/context-pack \
  -H 'content-type: application/json' \
  -d '{"items":[{"id":"system","tokens":300,"mandatory":true},{"id":"schema","tokens":500,"dependsOn":["system"],"priority":5},{"id":"history","tokens":4000,"priority":1},{"id":"notes","text":"Customer prefers email.","priority":3}],"budget":1000,"tokenizer":"o200k_base"}'

Input

FieldTypeRequiredDescription
itemsarray<object>; max 500 itemsyesUp to 500 items, 300000 characters of text in total.
budgetinteger; 1..100000000yesMaximum total tokens (including perItemOverhead per included item).
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.
perItemOverheadinteger; 0..100000noTokens added per included item for separators or wrappers. Default 0.

Example request body

{
  "items": [
    {
      "id": "system",
      "tokens": 300,
      "mandatory": true
    },
    {
      "id": "schema",
      "tokens": 500,
      "dependsOn": [
        "system"
      ],
      "priority": 5
    },
    {
      "id": "history",
      "tokens": 4000,
      "priority": 1
    },
    {
      "id": "notes",
      "text": "Customer prefers email.",
      "priority": 3
    }
  ],
  "budget": 1000,
  "tokenizer": "o200k_base"
}

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.
budgetintegerno
usedTokensintegernoTotal of included items; never above budget when status is pass.
remainingTokensintegerno
includedarray<object>; max 500 itemsnoIn input order.
excludedarray<object>; max 500 itemsno
mandatoryTokensintegernoCost of the mandatory items and their dependencies.
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