Skip to navigation

Count message tokens

Anthropic-compatible token counting for the Anthropic SDKs’ count_tokens. Send the same body as POST /v1/messages (max_tokens is not needed) and receive the size of its input as input_tokens, counting the system prompt, messages, and tool definitions. Each image and each PDF document counts as 258 tokens.

The count is an estimate; the usage on the message response is what is billed. No model runs and the request is not billed. It requires an API key and counts as one request toward your account rate limit. A model that is not in the catalog returns 404.

Authentication

AuthorizationBearer

Pass your EmpirioLabs API key as a bearer token. The Anthropic-style x-api-key header is also accepted on every endpoint.

Request

This endpoint expects an object.
modelstringRequired
The model the request is for.
messageslist of objectsRequired
systemstring or list of objectsOptional
toolslist of objectsOptional
Tool definitions, in the Anthropic format.

Response

The estimated input size.
input_tokensinteger
Estimated input tokens of the request.

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
429
Too Many Requests Error