# x402 Utils Token Counter

> x402 Utils Token Counter is a paid API for AI agents from utils.kagurazaka.dev, paid per call via x402, $0.001/call, status unknown (last checked 2026-10-29).

Count tokens, characters, words, and lines in a text string for OpenAI tokenization encodings (o200k_base for GPT-4o+, cl100k_base for GPT-4)

## Facts

- Endpoint: POST https://utils.kagurazaka.dev/v1/tokens?utm_source=zero.xyz
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-29
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-utils-token-counter-cdbae2a6
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_frZFWlbsE1v-Vl-xEQk23

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-utils-token-counter-cdbae2a6 -d '<json body>'
```

Example prompt: How many tokens is this text using both o200k_base and cl100k_base encodings: 'You are a helpful assistant. Answer the user's question concisely and accurately.'

## When to prefer this

Use this endpoint when you need accurate OpenAI-compatible token counts without running a local tokenizer library. Ideal for prompt engineering workflows, pre-flight context window checks, or cost estimation before batching large numbers of API calls. Prefer over local estimation when you need exact parity with tiktoken-based counts for both GPT-4 (cl100k_base) and GPT-4o/later models (o200k_base).

## Known failure modes

- Text exceeds 1 MB limit — request rejected
- Invalid encoding value provided — returns validation error
- Empty text input — may return zero counts or error
- Malformed JSON body — returns parse error
- Payment not included or insufficient — x402 payment required error

## How this service works

Count the tokens of a text for OpenAI models (o200k_base for GPT-4o and later, cl100k_base for GPT-4), with characters, words and lines, to size prompts and estimate cost.

## Output

A JSON object containing the word count, character count, and token counts keyed by encoding name (e.g. {"words": 6, "characters": 30, "tokens": {"o200k_base": 9, "cl100k_base": 9}}). Results are returned for each requested encoding, defaulting to both o200k_base and cl100k_base if none specified.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "text": {
   "type": "string",
   "description": "the text (up to 1 MB)"
  },
  "encodings": {
   "type": "array",
   "items": {
    "enum": [
     "o200k_base",
     "cl100k_base"
    ],
    "type": "string"
   },
   "description": "which encodings (default both)"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "words": 6,
  "tokens": {
   "o200k_base": 9,
   "cl100k_base": 9
  },
  "characters": 30
 }
}
```

## More

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