{"uid":"cap_LzIZD35cU6YOev3-LY6bU","slug":"writerslogic-context-packer-38af1ee0","name":"WritersLogic Context Packer","description":"Pay-per-call agents settled in USDC on Base via x402. Every response carries a signed provenance envelope.","url":"https://agents.writerslogic.com/api/v1/context-pack?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"items":{"type":"array","items":{"type":"object","required":["id"],"properties":{"id":{"type":"string","maxLength":100,"minLength":1,"description":"Unique id."},"text":{"type":"string","maxLength":100000,"description":"Content to count when tokens is not given."},"tokens":{"type":"integer","maximum":100000000,"minimum":0,"description":"Caller-supplied token count; always accepted and used in preference to counting text."},"priority":{"type":"number","maximum":1000000,"minimum":-1000000,"description":"Higher is packed first among optional items. Default 0."},"dependsOn":{"type":"array","items":{"type":"string","maxLength":100},"maxItems":50,"description":"Ids that must be included whenever this item is."},"mandatory":{"type":"boolean","description":"Always included, with its dependencies; if they cannot fit the result is fail."}},"additionalProperties":false},"maxItems":500,"minItems":1,"description":"Up to 500 items, 300000 characters of text in total."},"budget":{"type":"integer","maximum":100000000,"minimum":1,"description":"Maximum total tokens (including perItemOverhead per included item)."},"tokenizer":{"type":"string","maxLength":64,"description":"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."},"perItemOverhead":{"type":"integer","maximum":100000,"minimum":0,"description":"Tokens added per included item for separators or wrappers. Default 0."}}},"responseSchema":{"type":"json"},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.005","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.005/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_EEfWrUUNtSITg7Zckaxq9","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.005","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Selects which context items to include in an LLM prompt given a token budget, always including mandatory items and their dependencies, then greedily filling with optional items by descending priority.","exampleAgentPrompt":"I have 15 candidate context chunks for my next LLM call — items c1 through c15 — with a token budget of 4000 using the cl100k_base tokenizer. Items c1 and c2 are mandatory, c3 depends on c1, and the rest have priorities between 1 and 10. Which items should I include, adding 5 tokens of overhead per item for separators?","exampleUseCases":[{"title":"RAG prompt context selection","prompt":"I'm building a RAG pipeline and have 80 retrieved document chunks, each with a relevance score I want to use as priority. My prompt budget is 6000 tokens using cl100k_base, and my system prompt chunk is mandatory. Can you pack the best chunks that fit, adding 3 tokens per item for newline separators?"},{"title":"Agent memory window management","prompt":"My AI agent has 12 memory items — 2 of them are always required (the user's goal and the current task), and the rest are ranked by recency. The model context window allows 2048 tokens. Using o200k_base tokenizer with 4 tokens of overhead per item, which memory entries should I inject into the next prompt?"},{"title":"Multi-step dependency-aware context packing","prompt":"I have context items for a legal document assistant: some clauses depend on a definitions item being present, and a few items are mandatory. My token budget is 8000 with cl100k_base. Pack as many high-priority clauses as possible while always including the mandatory ones and respecting all the dependsOn relationships, with 10 tokens of overhead per included item."}],"resultDescription":"Returns a list of selected item IDs that fit within the token budget (all mandatory items and their dependencies guaranteed, then highest-priority optional items and their dependencies greedily added), along with the total token count used, per-item token counts, and a status indicating success or failure (e.g. 'fail' if mandatory items plus dependencies exceed the budget, 'unsupported' if the tokenizer is unrecognized and caller-supplied token counts are unavailable).","failureModes":["Mandatory items plus their dependencies exceed the token budget — returns fail status","Tokenizer name is not o200k_base or cl100k_base and no caller-supplied token counts provided — returns unsupported status for those items","Circular dependency among items — may cause unexpected behavior or incomplete packing","Item text missing and no caller-supplied token count — cannot count tokens for that item","More than 500 items or 300,000 total characters of text — request rejected","Token budget of 0 or negative — rejected by schema validation"],"whenToPreferThis":"Use this endpoint when you need deterministic, priority-ordered context selection for LLM prompts with hard token limits, especially when some items are mandatory, items have dependency relationships, and you need a fast greedy solution rather than an optimal knapsack. Prefer this over manual slicing when you have heterogeneous priorities, complex dependency graphs, or need reproducible packing logic. Not suitable when you need summarization or rewriting to fit content, or when you require an optimal (non-greedy) solution.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-19T06:37:56.098Z","isFirstParty":false,"canonicalSlug":"writerslogic-context-packer-38af1ee0"}