# agent402.tools LLM Token Counter

> agent402.tools LLM Token Counter is a paid API for AI agents from agent402.tools, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-15).

Counts exact LLM token count for a given string using real OpenAI BPE tokenizers (o200k_base or cl100k_base), deterministically and without calling a model.

## Facts

- Endpoint: POST https://agent402.tools/api/token-count
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agent402-tools-llm-token-counter-0b323411
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_hsrRbBl1SvUgZXXCE3RKv

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-tools-llm-token-counter-0b323411 -d '<json body>'
```

Example prompt: How many tokens is this text using the gpt-4o tokenizer: 'The quick brown fox jumps over the lazy dog. This is a test of the OpenAI BPE tokenizer for context window budgeting.'

## When to prefer this

Use this endpoint when you need a precise, deterministic token count using the real OpenAI BPE tokenizer — especially before sending a prompt to an LLM to ensure it fits within context window limits. Prefer this over approximate heuristics (e.g. word count / 0.75) or client-side tiktoken implementations when you need authoritative counts without standing up your own tokenizer. Ideal for agents managing prompt budgets, chunking documents, or validating inputs before costly LLM calls.

## Known failure modes

- Invalid or unsupported model name returns an error — only gpt-4o, gpt-4, and gpt-3.5 variants are recognized
- Empty or missing text field may return a zero count or validation error
- Extremely large text inputs may hit payload size limits
- Network or payment (x402) failure prevents the request from being processed

## How this service works

Count exact LLM tokens for a string using the real OpenAI BPE (o200k_base for gpt-4o/o-series, cl100k_base for gpt-4/gpt-3.5). Deterministic, offline - budget context windows without calling a model.

## Output

Returns the exact integer token count for the input text as tokenized by the specified OpenAI BPE tokenizer (o200k_base for gpt-4o/o-series models, cl100k_base for gpt-4/gpt-3.5 models), computed deterministically offline without any model API call.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "text": {
   "type": "string"
  },
  "model": {
   "type": "string",
   "description": "gpt-4o (default, o200k) | gpt-4 / gpt-3.5 (cl100k)"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "model": "gpt-4o",
  "tokens": 2,
  "encoding": "o200k_base",
  "characters": 11
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agent402-tools-llm-token-counter-0b323411/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agent402.tools](https://www.zero.xyz/host/agent402.tools/llms.txt)
