---
title: "Count input tokens"
method: POST
path: "/v1/messages/count_tokens"
tags: ["Anthropic Messages"]
---

# Count input tokens

`POST /v1/messages/count_tokens`

## Request

- Base URL: `https://api.abliteration.ai`
- URL: `https://api.abliteration.ai/v1/messages/count_tokens`
- Auth: one of:
  - HTTP bearer
  - API key in header `x-api-key`
- TypeScript: <https://skmtc.dev/abliteration/apis/abliteration-ai-api/docs/v1/messages/count_tokens/post.ts> (a function with typed inputs; its response is checked against the schema)

Returns an estimated input token count for a message payload without generating a response. Useful for budget checks before sending expensive prompts.

## Request body

- AnthropicMessagesRequest
  - `model` string, required: Model id (e.g. abliterated-model).
  - `messages` AnthropicMessage[], required: Non-empty array of message objects. Each has role (user or assistant) and content (string or content-block array).
    - `role` 'user' | 'assistant', required
    - `content` union, required: Text string or array of content blocks (text, image).
      - string
      - AnthropicContentBlock[]
        - union
          - object
            - `type` 'text', required
            - `text` string, required
          - object
            - `type` 'image', required
            - `source` object, required
              - …
  - `max_tokens` integer: Maximum number of tokens to generate.
  - `temperature` number: Sampling temperature.
  - `stream` boolean: Enable Server-Sent Events streaming.
  - `system` union: System prompt. Can be a string or an array of content blocks.
    - string
    - object[]
  - `flagged_categories` string[]: Optional moderation categories to block. Supported: harassment, hate, illicit, sexual. Self-harm and sexual/minors are always blocked.

## Response `200`

Token count

- AnthropicTokenCountResponse
  - `input_tokens` integer, required: Estimated number of input tokens.

## Other responses

- `400`: Invalid request
- `401`: Unauthorized
- `429`: Rate limited

---

[API](https://skmtc.dev/abliteration/apis/abliteration-ai-api.md) - [All operations](https://skmtc.dev/abliteration/apis/abliteration-ai-api/llms.txt) - [OpenAPI document](https://skmtc.dev/abliteration/apis/abliteration-ai-api/revisions/3a359f370787?raw)
