# Anthropic Token Counter via Locus x402

> Anthropic Token Counter via Locus x402 is a paid API for AI agents from anthropic.x402.paywithlocus.com, paid per call via x402, $0.001/call, status unknown (last checked 2026-09-14).

Counts the number of tokens that would be consumed by a given set of messages, system prompt, and tools for a specified Claude model, without sending a chat completion.

## Facts

- Endpoint: POST https://anthropic.x402.paywithlocus.com/anthropic/count-tokens
- Price: $0.001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/anthropic-token-counter-via-locus-x402-07a3e5a4
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_qTZF4LiOAi9PwQAAwG9bm

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 anthropic-token-counter-via-locus-x402-07a3e5a4 -d '<json body>'
```

Example prompt: Before sending this conversation to Claude claude-3-5-sonnet-20241022, can you count how many tokens the messages array plus the system prompt would use so I know if we're within the context limit?

## When to prefer this

Use this endpoint when you need to pre-check token consumption before committing to a full Claude chat completion call — ideal for cost estimation, context window validation, and prompt optimization workflows. Prefer this over making a full completion call when you only need token counts and want to avoid generating output. Particularly useful when iterating on system prompts or tool definitions and needing to stay within context limits.

## Known failure modes

- Invalid or unsupported model ID returns an error
- Malformed messages array (missing required fields) causes a 400-level error
- Payment failure or insufficient USDC balance causes the call to be rejected
- Messages exceed maximum allowed size for the token counting endpoint
- Missing required 'model' field results in validation error

## How this service works

Claude AI models — chat completions, vision, document processing, extended thinking, and tool use.

## Output

Returns a token count for the specified model given the provided messages, system prompt, and tool definitions. The response includes a data object with the count result, a payment record showing 0.001 USDC settled, and a request tracking ID with a status URL.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "model": {
   "type": "string"
  },
  "tools": {
   "type": "array",
   "items": {}
  },
  "system": {
   "anyOf": [
    {
     "type": "string"
    },
    {
     "type": "array",
     "items": {}
    }
   ]
  },
  "messages": {
   "type": "array",
   "items": {
    "type": "object",
    "required": [
     "role"
    ],
    "properties": {
     "name": {
      "type": "string"
     },
     "role": {
      "type": "string"
     },
     "content": {
      "anyOf": [
       {
        "type": "string"
       },
       {
        "type": "array",
        "items": {
         "type": "object",
         "required": [
          "type"
         ],
         "properties": {
          "text": {
           "type": "string"
          },
          "type": {
           "type": "string"
          },
          "image_url": {
           "type": "object",
           "required": [
            "url"
           ],
           "properties": {
            "url": {
             "type": "string"
            }
           },
           "additionalProperties": true
          }
         },
         "additionalProperties": true
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "tool_calls": {
      "type": "array",
      "items": {
       "type": "object",
       "additionalProperties": true
      }
     },
     "tool_call_id": {
      "type": "string"
     }
    },
    "additionalProperties": true
   }
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "data": {},
  "payment": {
   "scheme": "exact",
   "settledUsdc": "0.001000",
   "authorizedMaxUsdc": "0.001000"
  },
  "request": {
   "id": "00000000-0000-4000-8000-000000000000",
   "statusUrl": "/requests/00000000-0000-4000-8000-000000000000"
  },
  "success": true
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/anthropic-token-counter-via-locus-x402-07a3e5a4/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from anthropic.x402.paywithlocus.com](https://www.zero.xyz/host/anthropic.x402.paywithlocus.com/llms.txt)
