> ## 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 Anthropic Messages input tokens



## OpenAPI

````yaml https://api.abliteration.ai/openapi.json post /v1/messages/count_tokens
openapi: 3.1.0
info:
  title: Abliteration Platform API
  summary: Greenfield Abliteration backend and API gateway.
  version: 0.1.0
servers: []
security: []
paths:
  /v1/messages/count_tokens:
    post:
      tags:
        - Messages
      summary: Count Anthropic Messages input tokens
      operationId: countMessageTokens
      parameters:
        - name: Authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Bearer API key.
            title: Authorization
          description: Bearer API key.
        - name: x-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              API key alternative for Anthropic-compatible clients.
              Authorization takes precedence when both headers are present.
            title: X-Api-Key
          description: >-
            API key alternative for Anthropic-compatible clients. Authorization
            takes precedence when both headers are present.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicCountTokensRequest'
              description: Anthropic Messages count-tokens-compatible request.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicCountTokensResponse'
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not Found
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Conflict
        '413':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Request Entity Too Large
        '415':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Unsupported Media Type
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal Server Error
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad Gateway
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Service Unavailable
components:
  schemas:
    AnthropicCountTokensRequest:
      properties:
        model:
          type: string
          minLength: 1
          title: Model
        messages:
          items:
            $ref: '#/components/schemas/AnthropicMessage'
          type: array
          minItems: 1
          title: Messages
        system:
          anyOf:
            - type: string
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: System
        tools:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Tools
        tool_choice:
          anyOf:
            - $ref: '#/components/schemas/AnthropicToolChoice'
            - type: 'null'
        thinking:
          anyOf:
            - $ref: '#/components/schemas/AnthropicThinking'
            - type: 'null'
        output_config:
          anyOf:
            - $ref: '#/components/schemas/AnthropicOutputConfig'
            - type: 'null'
        context_management:
          anyOf:
            - $ref: '#/components/schemas/AnthropicContextManagement'
            - type: 'null'
      additionalProperties: false
      type: object
      required:
        - model
        - messages
      title: AnthropicCountTokensRequest
      description: Count request mirrors model-visible Messages inputs without generation.
    AnthropicCountTokensResponse:
      properties:
        input_tokens:
          type: integer
          minimum: 0
          title: Input Tokens
      additionalProperties: true
      type: object
      required:
        - input_tokens
      title: AnthropicCountTokensResponse
    ErrorResponse:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AnthropicMessage:
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
            - system
          title: Role
        content:
          anyOf:
            - type: string
            - items:
                additionalProperties: true
                type: object
              type: array
          title: Content
      additionalProperties: false
      type: object
      required:
        - role
        - content
      title: AnthropicMessage
    AnthropicToolChoice:
      properties:
        type:
          type: string
          enum:
            - auto
            - any
            - tool
            - none
          title: Type
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        disable_parallel_tool_use:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Disable Parallel Tool Use
      additionalProperties: false
      type: object
      required:
        - type
      title: AnthropicToolChoice
    AnthropicThinking:
      properties:
        type:
          type: string
          enum:
            - enabled
            - disabled
            - adaptive
          title: Type
        budget_tokens:
          anyOf:
            - type: integer
              maximum: 999990
              minimum: 1
            - type: 'null'
          title: Budget Tokens
        display:
          anyOf:
            - type: string
              enum:
                - summarized
                - omitted
            - type: 'null'
          title: Display
      additionalProperties: false
      type: object
      required:
        - type
      title: AnthropicThinking
    AnthropicOutputConfig:
      properties:
        effort:
          anyOf:
            - type: string
              enum:
                - low
                - medium
                - high
                - xhigh
                - max
                - ultracode
            - type: 'null'
          title: Effort
        format:
          anyOf:
            - $ref: '#/components/schemas/AnthropicJsonOutputFormat'
            - type: 'null'
      additionalProperties: false
      type: object
      title: AnthropicOutputConfig
    AnthropicContextManagement:
      properties:
        edits:
          items:
            $ref: '#/components/schemas/AnthropicClearThinkingContextEdit'
          type: array
          maxItems: 1
          minItems: 1
          title: Edits
      additionalProperties: false
      type: object
      required:
        - edits
      title: AnthropicContextManagement
      description: |-
        Supported beta context-management subset.

        ``keep=all`` does not remove any replayed thinking blocks, so it can be
        safely consumed at the compatibility boundary and omitted from the vLLM
        provider payload.
    ErrorDetail:
      properties:
        code:
          type: string
          title: Code
          description: Stable machine-readable error code.
        message:
          type: string
          title: Message
          description: Bounded human-readable error message.
        type:
          $ref: '#/components/schemas/ErrorType'
          description: Broad stable error category.
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
          description: Request field related to the error.
        request_id:
          type: string
          title: Request Id
          description: Server-owned canonical request ID.
        doc_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Doc Url
          description: Documentation URL for the error.
      type: object
      required:
        - code
        - message
        - type
        - request_id
      title: ErrorDetail
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    AnthropicJsonOutputFormat:
      properties:
        type:
          type: string
          const: json_schema
          title: Type
        schema:
          additionalProperties: true
          type: object
          title: Schema
      additionalProperties: false
      type: object
      required:
        - type
        - schema
      title: AnthropicJsonOutputFormat
    AnthropicClearThinkingContextEdit:
      properties:
        type:
          type: string
          const: clear_thinking_20251015
          title: Type
        keep:
          type: string
          const: all
          title: Keep
      additionalProperties: false
      type: object
      required:
        - type
        - keep
      title: AnthropicClearThinkingContextEdit
      description: Claude Code's non-destructive context-management compatibility edit.
    ErrorType:
      type: string
      enum:
        - auth_error
        - permission_error
        - validation_error
        - rate_limit_error
        - billing_error
        - moderation_error
        - media_error
        - not_found_error
        - conflict_error
        - provider_error
        - internal_error
      title: ErrorType

````