{"uid":"cap_ME8Um0fwPYZ_TNEY5ncJx","slug":"402utils-token-counter-bpe-tiktoken-4977ddac","name":"402utils Token Counter (BPE/tiktoken)","description":"Count BPE tokens in a text with tiktoken (o200k_base = GPT-4o default, or cl100k_base). An agent can check content fits an LLM context window before paying for an expensive call. Returns token count, char count and encoding. Honest scope: an OpenAI-style estimate — no open-source Claude tokenizer exists (exact Claude counts need the Anthropic API), Gemini differs too. Provided text only; nothing is fetched. Max 1 MB.","url":"https://402utils.com/v1/token-count?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"text":{"type":"string","description":"The text to tokenize (may be empty → 0 tokens; max 1 MB UTF-8)."},"encoding":{"enum":["o200k_base","cl100k_base"],"type":"string","default":"o200k_base","description":"tiktoken encoding. o200k_base = GPT-4o / GPT-4.1 / o-series (current standard); cl100k_base = GPT-3.5/4, text-embedding-3."}}},"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":{"p10Cents":"0.1000","medianCents":"0.1000","p90Cents":"0.1000","minCents":"0.1000","maxCents":"0.1000","p95Cents":"0.1000","sampleCount":1,"varies":false,"failureChargeRate":1},"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_LqPeODgwzIp-WGBjp-QMq","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 BPE tokens in a given text using tiktoken with o200k_base or cl100k_base encoding, returning token count, character count, and encoding used","exampleAgentPrompt":"Before I send this 10-page legal document to GPT-4o, can you count how many BPE tokens it contains using the o200k_base encoding so I know if it fits in the context window?","exampleUseCases":null,"resultDescription":"Returns a JSON object containing the integer token count for the provided text, the character count, and the encoding name used (o200k_base or cl100k_base). This lets the agent determine whether content fits within a model's context limit before making a costly LLM API call.","failureModes":["Text exceeds 1 MB UTF-8 limit — returns error indicating size constraint","Invalid encoding value supplied — returns validation error for the enum field","Empty POST body or missing text field — may return 0 tokens or a validation error","Network/payment failure — x402 payment of $0.001 USDC required; insufficient funds or wallet misconfiguration cause 402 error"],"whenToPreferThis":"Use this endpoint when an agent needs a fast, cheap pre-flight check before calling an OpenAI GPT-4o, GPT-4, GPT-3.5, or embedding model API to ensure the input fits the context window and to estimate token-based costs. Prefer o200k_base for GPT-4o/GPT-4.1/o-series and cl100k_base for GPT-3.5/GPT-4/text-embedding-3. Note: this gives OpenAI-style estimates only — it is not exact for Claude or Gemini tokenization.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-10T06:49:17.563Z","isFirstParty":false,"canonicalSlug":"402utils-token-counter-bpe-tiktoken-4977ddac"}