{"uid":"cap_mKPBKExc-6tCetJ2hR0Jp","slug":"agent-prep-text-truncate-94d43f03","name":"Agent Prep – Text Truncate","description":"Pre-LLM utilities for AI agents: structural JSON diff, JSON path listing, token estimation, text chunking, and truncation. Pay with USDC via x402 — no API keys.","url":"https://agent-prep.annushka1190.workers.dev/v1/text/truncate","method":"POST","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"body":{"type":"object"},"type":{"const":"http"},"method":{"enum":["POST"]},"bodyType":{"const":"json"}}}}},"responseSchema":{"type":"json","example":{"text":"Hello…","tokens":2,"truncated":true}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.003","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.003/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.003","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.003","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_krS6OTl85Tt93yg_mg4IM","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.003","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Truncates text to a specified token limit and returns the truncated text along with token count and truncation status.","exampleAgentPrompt":"Truncate this article text to fit within 500 tokens so I can safely include it in my LLM prompt, and tell me if it was actually cut.","exampleUseCases":[{"title":"Fitting context into prompt window","prompt":"I have a long customer support transcript I want to include in my GPT-4 prompt, but I need it capped at 800 tokens. Can you truncate it for me and let me know if anything was cut off?"},{"title":"RAG chunk pre-processing pipeline","prompt":"Before I send this retrieved document chunk to the model, truncate it to a maximum of 256 tokens so it doesn't blow out my context budget."},{"title":"Summarization input trimming","prompt":"I'm building a summarization pipeline and need to enforce a 1000-token ceiling on each input passage — truncate this text and tell me how many tokens it ended up being."}],"resultDescription":"Returns a JSON object containing: 'text' (the truncated string, with ellipsis if cut), 'tokens' (integer token count of the returned text), and 'truncated' (boolean indicating whether the original text was shortened).","failureModes":["Missing required 'input' body field returns a 400 validation error","Malformed JSON body causes a 400 parse error","Payment not provided or insufficient USDC causes a 402 Payment Required response","Extremely large inputs may time out on the Cloudflare Worker runtime","No token limit specified may result in default behavior or an error depending on server implementation"],"whenToPreferThis":"Choose this endpoint when you need a simple, pay-per-call, keyless text truncation utility that also returns a token count and truncation status — ideal for AI agent pipelines that need to enforce token budgets before calling an LLM. Prefer this over rolling your own tokenizer when you want a hosted, reliable solution without managing API keys, and when you're already using the x402 USDC payment flow for other Agent Prep utilities.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-13T12:41:56.774Z","isFirstParty":false}