# 402utils Token Counter (BPE/tiktoken)

> 402utils Token Counter (BPE/tiktoken) is a paid API for AI agents from 402utils.com, paid per call via x402, $0.001/call, status unknown (last checked 2026-10-10).

Counts BPE tokens in a given text using tiktoken with o200k_base or cl100k_base encoding, returning token count, character count, and encoding used

## Facts

- Endpoint: POST https://402utils.com/v1/token-count?utm_source=zero.xyz
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-10
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/402utils-token-counter-bpe-tiktoken-4977ddac
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ME8Um0fwPYZ_TNEY5ncJx

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability 402utils-token-counter-bpe-tiktoken-4977ddac -d '<json body>'
```

Example prompt: 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?

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

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.

## Output

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.

## Request schema (JSON Schema)

```json
{
 "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."
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/402utils-token-counter-bpe-tiktoken-4977ddac/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from 402utils.com](https://www.zero.xyz/host/402utils.com/llms.txt)
