# Count tokens
URL: https://docs.munito.ai/api/countMessageTokens

POST /messages/count_tokens

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

```json
{
  "operationId": "countMessageTokens",
  "parameters": [
    {
      "name": "munito-service-tier",
      "in": "header",
      "description": "priority, standard or flex. The response names the tier that is billed; see x-ratelimit-over-limit. See [Service tiers](https://docs.munito.ai/service-tiers).",
      "schema": {
        "type": "string",
        "enum": [
          "priority",
          "standard",
          "flex"
        ],
        "default": "standard"
      }
    },
    {
      "name": "munito-affinity",
      "in": "header",
      "description": "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.",
      "schema": {
        "type": "string"
      }
    }
  ],
  "summary": "Count tokens",
  "tags": [
    "Messages"
  ],
  "description": "Count the input tokens a Messages request would consume, without running it. Same request shape as POST /messages (minus `max_tokens`); free.",
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "messages"
          ],
          "properties": {
            "model": {
              "type": "string",
              "description": "Model id from GET /models.",
              "example": "qwen/qwen3.8-27b"
            },
            "messages": {
              "type": "array",
              "description": "The conversation as Anthropic-style messages: `content` is a string or an array of content blocks.",
              "items": {
                "type": "object",
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "user",
                      "assistant"
                    ]
                  },
                  "content": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "object"
                        },
                        "description": "Content blocks: `text`, `image`, `tool_use`, `tool_result` and `thinking`."
                      }
                    ]
                  }
                }
              }
            },
            "system": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "array",
                  "items": {
                    "type": "object"
                  },
                  "description": "`text` blocks."
                }
              ],
              "description": "System prompt (top-level, Anthropic-style): a string or an array of `text` blocks."
            }
          }
        },
        "example": {
          "model": "qwen/qwen3.8-27b",
          "messages": [
            {
              "role": "user",
              "content": "Explain intelligence sovereignty in one sentence."
            }
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "The input-token count.",
      "content": {
        "application/json": {
          "example": {
            "input_tokens": 18
          }
        }
      }
    }
  }
}
```

# Shared API schemas
{
  "securitySchemes": {
    "BearerAuth": {
      "type": "http",
      "scheme": "bearer",
      "description": "Your Munito API key."
    },
    "ApiKeyAuth": {
      "type": "apiKey",
      "in": "header",
      "name": "x-api-key",
      "description": "Your Munito API key."
    }
  }
}