{"uid":"cap_8qinnhDR7_IpOmsPkPhp4","slug":"x402-utils-token-counter-cc36111b","name":"x402 Utils — Token Counter","description":"Count the tokens of a text for OpenAI models (o200k_base for GPT-4o and later, cl100k_base for GPT-4), with characters, words and lines, to size prompts and estimate cost.","url":"https://qcb7fnxsbd7fbhj4.68r.lambda-web.us-east-1.on.aws/v1/tokens?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"text":{"type":"string","description":"the text (up to 1 MB)"},"encodings":{"type":"array","items":{"enum":["o200k_base","cl100k_base"],"type":"string"},"description":"which encodings (default both)"}}},"responseSchema":{"type":"json","example":{"words":6,"tokens":{"o200k_base":9,"cl100k_base":9},"characters":30}},"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_Tf5Z2UR1LHWqvr4j79Vf6","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, characters, words, and lines in a text for OpenAI models (o200k_base for GPT-4o+, cl100k_base for GPT-4) to help size prompts and estimate LLM costs.","exampleAgentPrompt":"Count the tokens in this text for both GPT-4o (o200k_base) and GPT-4 (cl100k_base): 'You are a helpful assistant. Please summarize the following article in three bullet points.'","exampleUseCases":[{"title":"Prompt budget check before LLM call","prompt":"Before I send this system prompt to GPT-4o, tell me how many tokens it uses with o200k_base encoding so I can see if it fits in the context window: 'You are an expert legal analyst. Review the contract and identify any clauses that may expose the company to liability...'"},{"title":"Cost estimation for batch processing","prompt":"I have this paragraph I'm going to send to GPT-4 thousands of times — can you count its tokens using cl100k_base so I can estimate my OpenAI bill? The text is: 'Extract the product name, price, and availability from the following e-commerce listing.'"},{"title":"Compare tokenization across model generations","prompt":"Count the tokens for both o200k_base and cl100k_base on this text so I can see how GPT-4 and GPT-4o tokenize it differently: 'The quick brown fox jumps over the lazy dog. 日本語テキストも含めます。'"}],"resultDescription":"A JSON object with token counts for each requested encoding (e.g. {\"o200k_base\": 9, \"cl100k_base\": 9}), plus top-level word count and character count for the input text.","failureModes":["Text exceeds 1 MB limit — request rejected","Invalid encoding name supplied — validation error returned","Empty text field — may return zero counts or an error","Network timeout on large inputs near the size limit","Payment not included or insufficient — HTTP 402 response"],"whenToPreferThis":"Choose this endpoint when you need accurate OpenAI-compatible token counts (tiktoken-based) for GPT-4 or GPT-4o models, especially when you need both encodings in one call along with word and character counts. Ideal for prompt sizing, context-window validation, and cost estimation workflows before making LLM API calls.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T12:36:12.992Z","isFirstParty":false,"canonicalSlug":"x402-utils-token-counter-cc36111b"}