# Token Count / Tokenizer Estimator (cl100k_base, o200k_base, Claude, Gemini)

> Token Count / Tokenizer Estimator (cl100k_base, o200k_base, Claude, Gemini) is a paid API for AI agents from x402-deployer.x402-deployer.workers.dev, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-14).

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.

## Facts

- Endpoint: POST https://x402-deployer.x402-deployer.workers.dev/token-count
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-cc1be628
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_xV1l0xS2glE9do15ZeNvI

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 x402-deployer-x402-deployer-workers-dev-cc1be628 -d '<json body>'
```

Example prompt: 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.'

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

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.

## Output

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.

## Example request

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

## Request schema (JSON Schema)

```json
{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "type": "object",
 "properties": {
  "input": {
   "type": "object",
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "type": "string",
     "enum": [
      "POST"
     ]
    },
    "bodyType": {
     "type": "string",
     "enum": [
      "json",
      "form-data",
      "text"
     ]
    },
    "body": {
     "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."
      }
     },
     "required": [
      "text"
     ]
    }
   },
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "properties": {
      "text_chars": {
       "type": "integer"
      },
      "model": {
       "type": "string"
      },
      "matched_tokenizer": {
       "type": "string"
      },
      "estimated_tokens": {
       "type": "integer"
      },
      "accuracy_note": {
       "type": "string"
      },
      "source": {
       "type": "string"
      }
     }
    }
   },
   "required": [
    "type"
   ]
  }
 },
 "required": [
  "input"
 ]
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-cc1be628/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402-deployer.x402-deployer.workers.dev](https://www.zero.xyz/host/x402-deployer.x402-deployer.workers.dev/llms.txt)
