API reference · Count tokens

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

POST/v1/messages/count_tokens

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

Example

curl https://api.layerx1.in/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." }]
  }'
Request
{ "input_tokens": 23 }
Response

Response fields

FieldNotes
input_tokensEstimated 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.