# Count Tokens in Messages (LLM API)

> Count Tokens in Messages (LLM API) is a paid API for AI agents from agents.llmapi.ai, paid per call via MPP, price unknown, status unknown (last checked 2026-10-17).

Returns the token count for a given set of messages against a specified model, without generating a response — free of charge.

## Facts

- Endpoint: POST https://agents.llmapi.ai/zc/v1/messages/count_tokens?utm_source=zero.xyz
- Price: price unknown
- Payment: MPP
- Status: unknown
- Last checked: 2026-10-17
- Activations on Zero: 0
- Provider: agents.llmapi.ai
- Website: https://agents.llmapi.ai
- Canonical page: https://www.zero.xyz/c/agents-llmapi-ai-count-tokens-in-messages-llm-api-ac2ad1d9
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_78eHLs1V3MZd5CbCdqLRW

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 agents-llmapi-ai-count-tokens-in-messages-llm-api-ac2ad1d9 -d '<json body>'
```

Example prompt: Before I send this conversation to claude-opus-5, can you check how many tokens it will use? The messages are: [{"role":"user","content":"Explain quantum entanglement in simple terms"}]

## When to prefer this

Use this endpoint when you need to check token usage before committing to an inference call — ideal for context window management, cost estimation, or prompt optimization. It is free, so it should be called proactively whenever there is uncertainty about whether a prompt fits within a model's context window. Prefer this over estimating tokens client-side, as tokenization rules differ per model and this endpoint uses the exact same tokenizer as the inference endpoint.

## Known failure modes

- Invalid model identifier returns a validation error — must be one of the supported enum values
- Malformed messages array (missing role or content fields) causes a 400 error
- Empty messages array may return zero or trigger a validation error
- Model-specific tokenization differences mean counts are model-specific and not interchangeable across models

## How this service works

Pre-flight token count for an Anthropic style request. Free.

## Output

Returns a JSON object with a single integer field `count` representing the total number of tokens the provided messages would consume for the specified model — no response text is generated.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "example": {
  "model": "claude-opus-5",
  "messages": [
   {
    "role": "user",
    "content": "hello"
   }
  ]
 },
 "required": [
  "model",
  "messages"
 ],
 "properties": {
  "model": {
   "enum": [
    "claude-opus-5",
    "claude-sonnet-5",
    "gpt-5.2",
    "gpt-5.1",
    "gpt-5-mini",
    "gemini-3.1-pro-preview",
    "gemini-3.7-flash",
    "deepseek-v4-pro",
    "deepseek-v4-flash",
    "grok-4.6",
    "kimi-k2.6",
    "glm-5.3"
   ],
   "type": "string",
   "description": "One of the storefront model ids."
  },
  "messages": {
   "type": "array",
   "items": {
    "type": "object"
   }
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "count": {
   "type": "integer"
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agents-llmapi-ai-count-tokens-in-messages-llm-api-ac2ad1d9/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agents.llmapi.ai](https://www.zero.xyz/host/agents.llmapi.ai/llms.txt)
