{"uid":"cap_frZFWlbsE1v-Vl-xEQk23","slug":"x402-utils-token-counter-cdbae2a6","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://utils.kagurazaka.dev/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_6SfKN0_mdrfIalJwMpUw5","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":"Count tokens, characters, words, and lines in a text string for OpenAI tokenization encodings (o200k_base for GPT-4o+, cl100k_base for GPT-4)","exampleAgentPrompt":"How many tokens is this text using both o200k_base and cl100k_base encodings: 'You are a helpful assistant. Answer the user's question concisely and accurately.'","exampleUseCases":[{"title":"Prompt size check before API call","prompt":"Before I send this system prompt to GPT-4o, count how many tokens it will use with o200k_base encoding: 'You are an expert data analyst. Your job is to help users understand complex datasets by providing clear, concise insights and visualizations.'"},{"title":"Cost estimation for batch job","prompt":"I have this text I'm about to send to thousands of GPT-4 API calls — count its tokens using cl100k_base so I can estimate my total cost: 'Summarize the following customer review in one sentence, focusing on the main sentiment.'"},{"title":"Context window fit check","prompt":"Can you check if this passage fits within a 128k token limit for GPT-4o? Count the tokens using o200k_base: 'The history of the Roman Empire spans over a thousand years, beginning with the traditional founding of Rome in 753 BC and lasting until the fall of Constantinople in 1453 AD.'"}],"resultDescription":"A JSON object containing the word count, character count, and token counts keyed by encoding name (e.g. {\"words\": 6, \"characters\": 30, \"tokens\": {\"o200k_base\": 9, \"cl100k_base\": 9}}). Results are returned for each requested encoding, defaulting to both o200k_base and cl100k_base if none specified.","failureModes":["Text exceeds 1 MB limit — request rejected","Invalid encoding value provided — returns validation error","Empty text input — may return zero counts or error","Malformed JSON body — returns parse error","Payment not included or insufficient — x402 payment required error"],"whenToPreferThis":"Use this endpoint when you need accurate OpenAI-compatible token counts without running a local tokenizer library. Ideal for prompt engineering workflows, pre-flight context window checks, or cost estimation before batching large numbers of API calls. Prefer over local estimation when you need exact parity with tiktoken-based counts for both GPT-4 (cl100k_base) and GPT-4o/later models (o200k_base).","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-29T12:37:33.840Z","isFirstParty":false,"canonicalSlug":"x402-utils-token-counter-cdbae2a6"}