> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abliteration.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Count input tokens

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



## OpenAPI

````yaml https://api.abliteration.ai/openapi.json post /v1/messages/count_tokens
openapi: 3.0.3
info:
  title: abliteration.ai API
  version: '2026-04-14'
  description: >-
    OpenAI-compatible chat completions and responses APIs for abliteration.ai,
    plus Anthropic-compatible messages and Policy Gateway endpoints for
    enforcement, config, simulations, and audits.
  termsOfService: https://abliteration.ai/terms-of-service
  contact:
    email: help@abliteration.ai
servers:
  - url: https://api.abliteration.ai
    description: Production
  - url: http://localhost:8080
    description: Local development
security: []
tags:
  - name: Chat Completions
    description: OpenAI-compatible chat completions.
  - name: Responses
    description: OpenAI-compatible Responses API.
  - name: Policy Gateway
    description: Policy-enforced chat completions.
  - name: Anthropic Messages
    description: Anthropic-compatible Messages API.
  - name: Models
    description: OpenAI-compatible model listing.
paths:
  /v1/messages/count_tokens:
    post:
      tags:
        - Anthropic Messages
      summary: Count input tokens
      description: >-
        Returns an estimated input token count for a message payload without
        generating a response. Useful for budget checks before sending expensive
        prompts.
      operationId: countAnthropicTokens
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicMessagesRequest'
            examples:
              basic:
                summary: Count tokens for a prompt
                value:
                  model: abliterated-model
                  messages:
                    - role: user
                      content: Count these tokens for me.
      responses:
        '200':
          description: Token count
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicTokenCountResponse'
              examples:
                success:
                  summary: 200 OK
                  value:
                    input_tokens: 12
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicErrorResponse'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
        - AnthropicApiKeyAuth: []
components:
  schemas:
    AnthropicMessagesRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model id (e.g. abliterated-model).
        messages:
          type: array
          description: >-
            Non-empty array of message objects. Each has role (user or
            assistant) and content (string or content-block array).
          items:
            $ref: '#/components/schemas/AnthropicMessage'
          minItems: 1
        max_tokens:
          type: integer
          minimum: 1
          description: Maximum number of tokens to generate.
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: Sampling temperature.
        stream:
          type: boolean
          default: false
          description: Enable Server-Sent Events streaming.
        system:
          description: System prompt. Can be a string or an array of content blocks.
          oneOf:
            - type: string
            - type: array
              items:
                type: object
        flagged_categories:
          type: array
          description: >-
            Optional moderation categories to block. Supported: harassment,
            hate, illicit, sexual. Self-harm and sexual/minors are always
            blocked.
          items:
            type: string
    AnthropicTokenCountResponse:
      type: object
      required:
        - input_tokens
      properties:
        input_tokens:
          type: integer
          description: Estimated number of input tokens.
    AnthropicErrorResponse:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          enum:
            - error
        error:
          type: object
          required:
            - type
            - message
          properties:
            type:
              type: string
              description: >-
                Error type (e.g. invalid_request_error, authentication_error,
                permission_error, api_error).
            message:
              type: string
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        code:
          type: string
    AnthropicMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          description: Text string or array of content blocks (text, image).
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/AnthropicContentBlock'
    AnthropicContentBlock:
      oneOf:
        - type: object
          required:
            - type
            - text
          properties:
            type:
              type: string
              enum:
                - text
            text:
              type: string
        - type: object
          required:
            - type
            - source
          properties:
            type:
              type: string
              enum:
                - image
            source:
              type: object
              required:
                - type
                - media_type
                - data
              properties:
                type:
                  type: string
                  enum:
                    - base64
                media_type:
                  type: string
                data:
                  type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a JWT or abliteration.ai API key as a Bearer token.
    AnthropicApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Anthropic SDK compatibility. Use an abliteration.ai API key starting
        with ak_.

````