{"uid":"cap_xV1l0xS2glE9do15ZeNvI","slug":"x402-deployer-x402-deployer-workers-dev-cc1be628","name":"Token Count / Tokenizer Estimator (cl100k_base, o200k_base, Claude, Gemini)","description":"Token count / tokenizer estimate / GPT-4 token count / Claude token count / Gemini token count / context-window pre-flight. Pure-local heuristic estimator targeting cl100k_base / o200k_base (GPT-4o) with calibrated multipliers for Claude and Gemini. Input model name is matched against an internal table of supported tokenizers. Accuracy ±5% versus tiktoken on typical English. No upstream call.","url":"https://x402-deployer.x402-deployer.workers.dev/token-count","method":"POST","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method","bodyType","body"],"properties":{"body":{"required":["text"],"properties":{"text":{"type":"string","description":"Text to count. Up to 1,000,000 chars."},"model":{"type":"string","description":"Target model. Examples: 'gpt-4o' (default), 'claude-sonnet-4-5', 'gemini-2-pro'. Free-form; matched against an internal multiplier table."}}},"type":{"type":"string","const":"http"},"method":{"enum":["POST"],"type":"string"},"bodyType":{"enum":["json","form-data","text"],"type":"string"}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"model":{"type":"string"},"source":{"type":"string"},"text_chars":{"type":"integer"},"accuracy_note":{"type":"string"},"estimated_tokens":{"type":"integer"},"matched_tokenizer":{"type":"string"}}}}}}},"responseSchema":null,"example":{"request":{"input":{"body":{"text":"You are a helpful assistant. Answer concisely and cite your sources whenever possible. Do not make up information.","model":"gpt-4o"},"type":"http","method":"POST","bodyType":"json"}},"response":{"model":"gpt-4o","source":"DIY heuristic (cl100k_base-shaped)","text_chars":114,"accuracy_note":"Heuristic estimate, ±5% vs tiktoken cl100k_base on typical English text. Larger error on heavy punctuation, code, or non-Latin scripts. Pure-local — no upstream call.","estimated_tokens":41,"matched_tokenizer":"gpt-4o"}},"exampleRequest":{"text":"You are a helpful assistant. Answer concisely and cite your sources whenever possible. Do not make up information.","model":"gpt-4o"},"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"settled","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__tid4ZZMd-H3E6aeLpj8s","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":null,"unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Estimates the token count for a given text against a specified model's tokenizer (GPT-4, GPT-4o, Claude, Gemini) using a pure-local heuristic with ±5% accuracy versus tiktoken — no upstream API call required.","exampleAgentPrompt":"How many tokens will this system prompt use if I send it to GPT-4o? The text is: 'You are a helpful assistant. Answer concisely and cite your sources whenever possible. Do not make up information.'","exampleUseCases":null,"resultDescription":"Returns a token count estimate for the provided text under the specified model's tokenizer, along with which tokenizer was matched internally (e.g. cl100k_base or o200k_base), calibrated multipliers applied for Claude/Gemini, and a note on expected accuracy (±5% vs tiktoken on typical English). No external API is called.","failureModes":["Unsupported or unrecognized model name — returns error or falls back to default tokenizer","Empty or missing text input — returns validation error","Token count for non-English text may exceed ±5% accuracy bounds","Very long inputs may time out on the worker edge runtime"],"whenToPreferThis":"Choose this endpoint when you need a fast, cheap, local token count estimate before making an LLM API call — especially for context-window pre-flight checks, prompt budgeting, or cost estimation. Prefer it over calling tiktoken directly when you need a hosted, zero-dependency solution that covers GPT-4, GPT-4o, Claude, and Gemini in one call. Not ideal when exact token counts are required or when the text is highly non-English.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-14T12:40:39.445Z","isFirstParty":false}