{"uid":"cap_Fxu4VVmuoIrUpHLx2kKiC","slug":"defi-intel-agent-gateway-token-counter-trimmer-6cbcbb71","name":"DeFi Intel Agent Gateway – Token Counter & Trimmer","description":"Estimate exact token count (tiktoken-style) and trim text to a budget — $0.001 USDC/call on eip155:8453. Pay-per-call via x402 — no API key, no account. Free samples daily.","url":"https://defi-intel-agent-gateway.gg-neo15.workers.dev/v1/text/token-counter-trimmer","method":"POST","headers":{},"bodySchema":null,"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","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.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_IFHik6Ku8H-zglzMhsjfX","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Counts tokens in text (tiktoken-style) and trims text to a specified token budget, returning exact counts and truncated output.","exampleAgentPrompt":"Count the exact number of tokens in this text and trim it down to 3000 tokens if it exceeds that: 'The quick brown fox... [long document]'. Use tiktoken-style counting.","exampleUseCases":[{"title":"Prompt budget enforcement before LLM call","prompt":"Before I send this 10-page document to GPT-4, count how many tokens it is and trim it to 6000 tokens so it fits within the context window."},{"title":"Checking RAG chunk size","prompt":"I'm building a retrieval pipeline — can you count the tokens in each of these text chunks and tell me which ones exceed 512 tokens so I know which need splitting?"},{"title":"Trimming scraped content for summarization","prompt":"I just scraped this long article and need to feed it to a summarizer limited to 2048 tokens — please trim it to exactly 2048 tokens without cutting mid-sentence if possible."}],"resultDescription":"Returns the exact token count of the input text (tiktoken-compatible) and, if a trim budget is specified, returns the text truncated to fit within that token budget along with the resulting token count.","failureModes":["Empty or missing input text returns a 400 validation error","Token budget set to zero or negative value may return error or empty string","Very large inputs may time out at edge runtime","Malformed JSON body returns 422 unprocessable entity","Payment failure (insufficient USDC balance) returns 402 Payment Required"],"whenToPreferThis":"Choose this endpoint when you need precise tiktoken-compatible token counting or trimming without setting up an API key or account — ideal for pay-per-call agent workflows on Base that need to enforce LLM context window limits before making expensive model calls. Prefer over client-side tokenizers when you need server-side determinism or are operating in a sandboxed environment without tiktoken installed.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-14T12:49:56.963Z","isFirstParty":false}