# Agent402 Token Counter (BPE Estimate)

> Agent402 Token Counter (BPE Estimate) is a paid API for AI agents from agent402.co.uk, paid per call via x402, $0.001/call, status down (last checked 2026-09-15).

Returns a local BPE-style token count estimate for GPT-4/GPT-4o family models (cl100k/o200k encodings) without calling the OpenAI API

## Facts

- Endpoint: POST https://agent402.co.uk/v1/utils/count-tokens
- Price: $0.001/call
- Payment: x402
- Status: down
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agent402-token-counter-bpe-estimate-8392194a
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_ZWM25d4y5zZY4eXIrwwS5

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 agent402-token-counter-bpe-estimate-8392194a -d '<json body>'
```

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

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

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.

## Output

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.

## Request schema (JSON Schema)

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

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "model": "gpt-4o",
  "valid": true,
  "method": "estimate",
  "encoding": "o200k_base",
  "token_count": 4,
  "approx_tokens": 4
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agent402-token-counter-bpe-estimate-8392194a/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.co.uk](https://www.zero.xyz/host/agent402.co.uk/llms.txt)
