> ## Documentation Index
> Fetch the complete documentation index at: https://docs.layerx1.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Count tokens.

> A fast estimate of the input tokens a Messages request will consume — the endpoint context meters (including Claude Code's) call before sending.

## Endpoint

```http theme={null}
POST /v1/messages/count_tokens
```

Anthropic-compatible: send the same body you would send to
[/v1/messages](/api/messages) — `model`, `system`, `messages`, `tools` — and get a token
count back without generating anything.

## Example

```sh title="Request" theme={null}
curl https://api.layerx1.com/v1/messages/count_tokens \
  -H "x-api-key: $LAYERX1_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "lx1-sonnet-4.6",
    "system": "You are concise.",
    "messages": [{ "role": "user", "content": "Summarize this repo." }]
  }'
```

```json title="Response" theme={null}
{ "input_tokens": 23 }
```

## Response fields

| Field          | Notes                                                |
| -------------- | ---------------------------------------------------- |
| `input_tokens` | Estimated input tokens for the request body as sent. |

<Note>
  The count is an **estimate for budgeting**, not an invoice: use it to decide what fits
  in a context window. Billing always uses the exact usage counts returned on the response
  that actually generates.
</Note>
