{"uid":"cap_BEX2blfKydIGhnJ-RwEyK","slug":"openverbs-token-counter-5d960306","name":"OpenVerbs Token Counter","description":"Count the LLM tokens in text for a given model or encoding — exact for OpenAI and open models (Llama, Mistral, Qwen, Gemma, DeepSeek, Command-R); labelled-approximate for Claude & Gemini.","url":"https://tokens.openverbs.com/v1/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":{"type":"object","required":["text"],"properties":{"text":{"type":"string","maxLength":100000,"description":"The text to tokenize. Empty string counts as 0 tokens."},"model":{"type":"string","maxLength":100,"minLength":1,"description":"LLM model name, e.g. \"gpt-4o\", \"llama-3.1-70b\", \"claude-3-5-sonnet\". Resolved to its tokenizer. Defaults to gpt-4o. Supported families: o200k_base, cl100k_base, p50k_base, r50k_base, llama3, llama2, mistral, qwen, gemma, deepseek, command-r, claude, gemini."},"encoding":{"enum":["o200k_base","cl100k_base","p50k_base","r50k_base"],"type":"string","description":"Explicit OpenAI BPE encoding. Overrides \"model\" and is always exact. Defaults to o200k_base."}},"additionalProperties":false},"type":{"type":"string","const":"http"},"method":{"enum":["POST"],"type":"string"},"bodyType":{"enum":["json","form-data","text"],"type":"string"}},"additionalProperties":false}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.004","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.004/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.004","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_XTq9CVhapts0kpN5jL_bi","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.004","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Counts the exact number of LLM tokens in a given text string for a specified model or encoding, supporting OpenAI, Llama, Mistral, Qwen, Gemma, DeepSeek, Command-R, Claude, and Gemini.","exampleAgentPrompt":"How many tokens is this text using the gpt-4o tokenizer: 'Large language models process text by breaking it into tokens, and understanding token counts is essential for managing API costs and context window limits.'","exampleUseCases":[{"title":"Pre-flight context window check","prompt":"Before I send this 5,000-word document to the claude-3-5-sonnet API, can you tell me how many tokens it will use so I know if it fits within the context window?"},{"title":"Prompt cost estimation for gpt-4o","prompt":"Count the tokens in this system prompt using the gpt-4o model so I can estimate how much each API call will cost: 'You are a helpful assistant that answers questions about software engineering.'"},{"title":"Llama-3 tokenization for fine-tuning","prompt":"How many tokens does this training example have when tokenized for llama-3.1-70b? The text is: 'The quick brown fox jumps over the lazy dog. This sentence is often used in typography.'"}],"resultDescription":"Returns the integer token count for the provided text under the specified model or encoding, along with the resolved tokenizer/encoding name. For OpenAI models and open-source models (Llama, Mistral, Qwen, Gemma, DeepSeek, Command-R), counts are exact; for Claude and Gemini, counts are labelled as approximate.","failureModes":["Text exceeds 100,000 character limit — returns validation error","Unknown or unsupported model name — falls back to default gpt-4o tokenizer or returns error","Empty string input — returns 0 tokens successfully","Invalid encoding enum value — returns schema validation error","Payment failure via x402 protocol — returns 402 Payment Required before processing"],"whenToPreferThis":"Choose this endpoint when you need accurate, model-specific token counts before making LLM API calls — especially for cost estimation, context window validation, or prompt engineering. It supports the widest range of model families (OpenAI, Llama, Mistral, Qwen, Gemma, DeepSeek, Command-R, Claude, Gemini) in a single API, making it preferable to rolling your own tiktoken/sentencepiece integration or using model-provider estimations that may be inaccurate.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-14T12:34:21.388Z","isFirstParty":false}