{"uid":"cap_FSD_ZkRaJ2F-bGn7yTaXB","slug":"agentutility-token-count-estimator-ab42e0f2","name":"AgentUtility Token Count Estimator","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.agentutility.ai/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":{"type":"json","example":{"model":"gpt-4o","source":"DIY heuristic (cl100k_base-shaped)","text_chars":46,"accuracy_note":"Heuristic estimate, ±5% vs tiktoken cl100k_base on typical English text. Larger error on heavy punctuation, code, or non-Latin scripts. Computed locally in-process — instant response.","estimated_tokens":11,"matched_tokenizer":"gpt-4o"}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.005","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.005/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_gx-sf3thxm27u_wA47chs","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.005","costPer":"request","priority":0,"asset":null,"unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Estimates token count for a given text and target LLM (GPT-4, Claude, Gemini) using a local heuristic based on cl100k_base/o200k_base tokenizers with model-calibrated multipliers — no upstream API call.","exampleAgentPrompt":"How many tokens would this system prompt use if I send it to GPT-4o? Here's the text: 'You are a helpful assistant. Always respond concisely and cite your sources.' — I need to know before I make the call.","exampleUseCases":[{"title":"Pre-flight context window check","prompt":"Before I send this 10,000-word document to Claude, can you estimate how many tokens it is so I know if it'll fit in a 100k context window?"},{"title":"LLM cost budgeting for GPT-4o","prompt":"I'm about to run a batch of prompts through GPT-4o and want to estimate the total token count for this sample text so I can project my costs — can you count the tokens?"},{"title":"Multi-model token comparison","prompt":"I have this prompt text and I want to know how the token count compares between GPT-4o and Gemini — can you estimate tokens for both models?"}],"resultDescription":"Returns a numeric token count estimate for the provided text under the specified model's tokenizer, along with the resolved tokenizer name and an accuracy disclaimer of approximately ±5% versus tiktoken on typical English text. No external API call is made — result is computed locally.","failureModes":["Unsupported model name returns an error or falls back to default tokenizer","Very short or empty text may produce zero or near-zero counts","Non-English or code-heavy text may exceed the ±5% accuracy bound","Malformed request body returns a 400 error","Payment not settled via x402 returns a 402 Payment Required error"],"whenToPreferThis":"Choose this endpoint when you need a fast, cheap, offline token estimate before committing to an LLM API call — especially useful for context-window pre-flight checks, cost budgeting, or batch processing where calling tiktoken or a live tokenizer API is not feasible. Prefer over live tokenizer APIs when latency or cost of upstream calls matters. Best for English text targeting GPT-4, GPT-4o, Claude, or Gemini.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T07:12:29.062Z","isFirstParty":false}