Count Message Tokens
Prompt-token count for a Messages request, without running inference.
Bills nothing and writes no usage row. The body is Anthropic’s
{"input_tokens": N}; X-Mesh-Token-Count-Source says whether the
provider counted it (exact) or the gateway estimated it (estimate).
Authorizations
Enter your MeshAPI key (rsk_...) or, for the admin-keys endpoints, a dashboard session token — sent as Authorization: Bearer <token>.
Headers
Dated version of the API contract to pin this request to. Omit it and the request is served under 2026-08 — the oldest supported version, so an existing integration is never moved by a release. A malformed or unsupported value is rejected with 400 invalid_api_version rather than falling back silently. The version actually served is echoed as X-Mesh-Version on every response, including errors.
2026-08, 2026-09, 2026-11 Body
POST /v1/messages/count_tokens body.
Counting needs no output limit, so max_tokens is optional here while the
inference schema keeps it required.
x >= 10 <= x <= 10 <= x <= 1Your own labels for this request, echoed back on the usage row and available as a filter and a group-by dimension in the usage API. String keys to string values. Never put personal or sensitive data here — tags are stored with the usage record and are not redacted.
A stable, anonymised identifier for the end user making this request, recorded on the usage row and available as a filter and a group-by dimension in the usage API. Supersedes the deprecated user field. Use an opaque id, not an email address or a name.
256Pin this request to one upstream provider, e.g. bedrock. The request is served by that provider or refused — never routed elsewhere. See GET /v1/providers/pinnable for the slugs this deployment accepts.
Response
Successful Response