{"uid":"cap_ZWM25d4y5zZY4eXIrwwS5","slug":"agent402-token-counter-bpe-estimate-8392194a","name":"Agent402 Token Counter (BPE Estimate)","description":"Don't burn tokens on deterministic work. Go/no-go jobs first: payout preflight, text firewall (PII/secrets), budget check — then rails, calendars, finmath. x402 USDC on Base. UK + global. agent402.co.uk — not agent402.tools. $0.001–$0.002 USDC on Base. No API keys.","url":"https://agent402.co.uk/v1/utils/count-tokens","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"text":{"type":"string","description":"Text to count (UTF-8, max 500k chars)"},"model":{"type":"string","description":"Model id or encoding: gpt-4o | cl100k_base | o200k_base | …"},"encoding":{"type":"string","description":"Alias for model: cl100k_base | o200k_base"}}},"responseSchema":{"type":"json","example":{"model":"gpt-4o","valid":true,"method":"estimate","encoding":"o200k_base","token_count":4,"approx_tokens":4}},"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":"down","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_ONLYifmx_swCzDFr4gKtI","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":"Returns a local BPE-style token count estimate for GPT-4/GPT-4o family models (cl100k/o200k encodings) without calling the OpenAI API","exampleAgentPrompt":"How many tokens is this text using the gpt-4o encoding — 'The quick brown fox jumps over the lazy dog. This is a test of token counting for a prompt I'm about to send.'?","exampleUseCases":[{"title":"Pre-flight context window check","prompt":"Before I send this 10-page legal document to gpt-4o, can you count how many tokens it is? Here's the text: [document]. I need to know if it fits in the 128k context window."},{"title":"Prompt cost estimation pipeline","prompt":"I'm building an agent pipeline and need to estimate token costs before each OpenAI call. Count the tokens in this system prompt using gpt-4o encoding so I can budget the API spend: 'You are a helpful assistant that summarizes financial reports...'"},{"title":"Batch text sizing for chunking","prompt":"I need to split this article into chunks that are each under 2000 tokens for cl100k_base. Can you count the tokens in this section first: 'Inflation remained elevated throughout Q3...'"}],"resultDescription":"Returns a JSON object with approx_tokens (integer token estimate), token_count (same value), model (resolved model name e.g. 'gpt-4o'), encoding (e.g. 'o200k_base'), method ('estimate'), and valid (boolean). The estimate is computed locally using BPE heuristics — not via the OpenAI API — so it is fast and cheap but may differ slightly from exact tiktoken counts.","failureModes":["Text exceeds 500k character limit — request rejected","Unknown or unsupported model/encoding string — may return invalid:true or error","Empty text input — may return 0 tokens or validation error","Malformed JSON body — HTTP 400","Service unavailable — HTTP 5xx"],"whenToPreferThis":"Choose this endpoint when you need a fast, cheap token count estimate for GPT-4 or GPT-4o family models (cl100k or o200k encodings) without incurring OpenAI API costs or latency. At $0.001 per call it is 3x cheaper than alternatives. Ideal for agent pipelines that need to gate or budget API calls, chunk documents, or validate context window fit before submitting to OpenAI. Not suitable when exact tiktoken precision is required or when using non-OpenAI model families.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T14:28:45.201Z","isFirstParty":false}