# AgentUtility Token Count Estimator

> AgentUtility Token Count Estimator is a paid API for AI agents from x402.agentutility.ai, paid per call via x402, $0.005/call, status unknown (last checked 2026-09-15).

Estimates token count for a given text and target LLM (GPT-4, Claude, Gemini) using a local heuristic based on cl100k_base/o200k_base tokenizers with model-calibrated multipliers — no upstream API call.

## Facts

- Endpoint: POST https://x402.agentutility.ai/token-count
- Price: $0.005/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/agentutility-token-count-estimator-ab42e0f2
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_FSD_ZkRaJ2F-bGn7yTaXB

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 agentutility-token-count-estimator-ab42e0f2 -d '<json body>'
```

Example prompt: How many tokens would this system prompt use if I send it to GPT-4o? Here's the text: 'You are a helpful assistant. Always respond concisely and cite your sources.' — I need to know before I make the call.

## When to prefer this

Choose this endpoint when you need a fast, cheap, offline token estimate before committing to an LLM API call — especially useful for context-window pre-flight checks, cost budgeting, or batch processing where calling tiktoken or a live tokenizer API is not feasible. Prefer over live tokenizer APIs when latency or cost of upstream calls matters. Best for English text targeting GPT-4, GPT-4o, Claude, or Gemini.

## Known failure modes

- Unsupported model name returns an error or falls back to default tokenizer
- Very short or empty text may produce zero or near-zero counts
- Non-English or code-heavy text may exceed the ±5% accuracy bound
- Malformed request body returns a 400 error
- Payment not settled via x402 returns a 402 Payment Required error

## How this service works

Token count / tokenizer estimate / GPT-4 token count / Claude token count / Gemini token count / context-window pre-flight. Pure-local heuristic estimator targeting cl100k_base / o200k_base (GPT-4o) with calibrated multipliers for Claude and Gemini. Input model name is matched against an internal table of supported tokenizers. Accuracy ±5% versus tiktoken on typical English. No upstream call.

## Output

Returns a numeric token count estimate for the provided text under the specified model's tokenizer, along with the resolved tokenizer name and an accuracy disclaimer of approximately ±5% versus tiktoken on typical English text. No external API call is made — result is computed locally.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "properties": {
    "body": {
     "required": [
      "text"
     ],
     "properties": {
      "text": {
       "type": "string",
       "description": "Text to count. Up to 1,000,000 chars."
      },
      "model": {
       "type": "string",
       "description": "Target model. Examples: 'gpt-4o' (default), 'claude-sonnet-4-5', 'gemini-2-pro'. Free-form; matched against an internal multiplier table."
      }
     }
    },
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "POST"
     ],
     "type": "string"
    },
    "bodyType": {
     "enum": [
      "json",
      "form-data",
      "text"
     ],
     "type": "string"
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "properties": {
      "model": {
       "type": "string"
      },
      "source": {
       "type": "string"
      },
      "text_chars": {
       "type": "integer"
      },
      "accuracy_note": {
       "type": "string"
      },
      "estimated_tokens": {
       "type": "integer"
      },
      "matched_tokenizer": {
       "type": "string"
      }
     }
    }
   }
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "model": "gpt-4o",
  "source": "DIY heuristic (cl100k_base-shaped)",
  "text_chars": 46,
  "accuracy_note": "Heuristic estimate, ±5% vs tiktoken cl100k_base on typical English text. Larger error on heavy punctuation, code, or non-Latin scripts. Computed locally in-process — instant response.",
  "estimated_tokens": 11,
  "matched_tokenizer": "gpt-4o"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agentutility-token-count-estimator-ab42e0f2/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402.agentutility.ai](https://www.zero.xyz/host/x402.agentutility.ai/llms.txt)
