# x402-tools Token Counter

> x402-tools Token Counter is a paid API for AI agents from x402.nichospt.net, paid per call via x402, $0.01/call, status unknown (last checked 2026-10-11).

Counts the number of BPE tokens in a text string using GPT-4o or GPT-4 encodings, optionally estimating cost at a given price per million tokens.

## Facts

- Endpoint: POST https://x402.nichospt.net/count-tokens?utm_source=zero.xyz
- Price: $0.01/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-11
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-tools-token-counter-a729bfea
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_p876qZufWlf7k4ot1QJYu

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

Example prompt: How many tokens is this text using the o200k_base encoding, and what would it cost at $5 per million tokens: 'The quick brown fox jumps over the lazy dog'?

## When to prefer this

Use this endpoint when you need a fast, pay-per-call token count for GPT-4o (o200k_base) or GPT-4/3.5/embeddings (cl100k_base) text without running a local tokenizer. Ideal for agents that need to check prompt size, estimate API costs, or validate context window fit before making an LLM call.

## Known failure modes

- Text exceeds 1,000,000 character limit — request rejected
- Invalid encoding value (not cl100k_base or o200k_base) — validation error
- Missing text field — required parameter error
- Payment not settled via x402 protocol — 402 Payment Required response

## How this service works

Pay-per-call utility APIs for AI agents, settled in USDC via the x402 protocol.

## Output

A JSON object with the encoding used, total token count, character count of the input, and optionally an estimated cost in USD if price_per_1m was provided.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "text": {
   "type": "string",
   "maxLength": 1000000,
   "description": "Text to tokenize"
  },
  "encoding": {
   "enum": [
    "cl100k_base",
    "o200k_base"
   ],
   "type": "string",
   "default": "o200k_base",
   "description": "BPE encoding. o200k_base = GPT-4o/o1; cl100k_base = GPT-4/3.5/embeddings."
  },
  "price_per_1m": {
   "type": "number",
   "minimum": 0,
   "description": "Optional USD price per 1M tokens; if set, estimated_cost is returned."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "encoding": "o200k_base",
  "token_count": 5,
  "estimated_cost": 0.0000125,
  "character_count": 20
 }
}
```

## More

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