# Token Counter by utilsforagents.com

> Token Counter by utilsforagents.com is a paid API for AI agents from utilsforagents.com, paid per call via x402, $0.003/call, status unknown (last checked 2026-10-11).

Counts the number of tokens in a text string using a specified LLM tokenizer encoding (GPT-4, GPT-4o, Claude, or Gemini)

## Facts

- Endpoint: POST https://utilsforagents.com/v1/utilities/count-tokens?utm_source=zero.xyz
- Price: $0.003/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-11
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/utilsforagents-com-44c1f37d
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_AkRzT8eW39-eajaScYZyc

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 utilsforagents-com-44c1f37d -d '<json body>'
```

Example prompt: How many tokens is this text using the cl100k_base encoding so I know if it fits in GPT-4's context window: 'The quick brown fox jumps over the lazy dog. This is a test of the tokenizer utility.'

## When to prefer this

Use this endpoint when you need an accurate or estimated token count before calling an LLM, to avoid context window overflows, estimate API costs, or enforce token budgets. Prefer cl100k_base for GPT-4/GPT-3.5 (exact BPE), o200k_base for GPT-4o (exact BPE), claude for Anthropic models (estimated), or gemini for Google models (estimated). Also use for base64-encoded images with content_type='image' for vision tile-based estimation.

## Known failure modes

- Text exceeds 50 MB limit — request rejected
- Unsupported encoding value provided — error returned
- Empty text field — may return 0 or validation error
- Malformed JSON body — 400 error
- content_type='image' used with non-base64 text — incorrect tile-based estimate

## How this service works

Pay-per-call AI agent utilities plus a free feedback endpoint: JSON diff, EXIF extraction, metadata scrubbing, HTML-to-Markdown, URL fetching, and feature-request collection. $0.003/call for paid utility routes via x402 on Base or Solana.

## Output

Returns the integer token count for the submitted text under the specified encoding, allowing the agent to estimate LLM costs, check context window fit, or enforce token budgets before making an LLM API call.

## Example request

```json
{
 "text": "The quick brown fox jumps over the lazy dog. This is a test of the tokenizer utility.",
 "encoding": "cl100k_base"
}
```

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "text": {
   "type": "string",
   "description": "Text to tokenize (max 50 MB)"
  },
  "encoding": {
   "enum": [
    "cl100k_base",
    "o200k_base",
    "claude",
    "gemini"
   ],
   "type": "string",
   "description": "Tokenizer encoding (default: cl100k_base)"
  },
  "content_type": {
   "enum": [
    "text",
    "image"
   ],
   "type": "string",
   "description": "Set to 'image' if text is a base64-encoded image (uses tile-based token estimation). Auto-detected for JPEG, PNG, and GIF base64 prefixes even if not set. Default: 'text'."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "ok": true,
  "method": "exact",
  "encoding": "cl100k_base",
  "tokenCount": 4,
  "utf8Sanitized": false,
  "characterCount": 13,
  "processingTimeMs": 1.23
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/utilsforagents-com-44c1f37d/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from utilsforagents.com](https://www.zero.xyz/host/utilsforagents.com/llms.txt)
