Skip to Content

Count tokens

Count the input tokens a Messages request would consume, without running it. Same request shape as POST /messages (minus max_tokens); free.

POST
/messages/count_tokens

Authorization

headerAuthorizationBearer <token>

Your Munito API key.

Header Parameters

munito-service-tier?string

priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit. See Service tiers.

Default"standard"
Value in"priority""standard""flex"
munito-affinity?string

An opaque token. Send it back with the next request of the conversation, so that the prompt cache can serve it. Without it, the API uses prompt_cache_key, x-session-affinity or user, or metadata.user_id on the Messages API, for the same purpose.

Request Body

application/json
  1. body
model*string

Model id from GET /models.

messages*array<>

The conversation as Anthropic-style messages: content is a string or an array of content blocks.

system?|array<>

System prompt (top-level, Anthropic-style): a string or an array of text blocks.

Response Body

The input-token count.

application/json
curl -X POST 'https://api.munito.ai/inference/v1/messages/count_tokens' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "qwen/qwen3.8-27b",
  "messages": [
    {
      "role": "user",
      "content": "Explain intelligence sovereignty in one sentence."
    }
  ]
}'
Example Response200
{
  "input_tokens": 18
}