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

# Count Tokens

> Anthropic Messages token-counting compatible endpoint. Returns the number of input tokens a Messages request would consume, without creating a message. Mirrors Anthropic's POST /v1/messages/count_tokens (same request body as the Messages endpoint, minus the required max_tokens). Supported for Claude models; other models return 400.



## OpenAPI

````yaml post /v3/compat/v1/messages/count_tokens
openapi: 3.1.0
info:
  description: Schema-driven generative API that orchestrates LLM-powered workflows.
  title: Task API
  version: 3.0.0
servers:
  - description: Production
    url: https://api.opper.ai
  - description: Local development
    url: http://localhost:8080
security:
  - BearerAuth: []
tags:
  - description: Schema-driven function management and execution
    name: Functions
  - description: OpenAI-compatible chat completions
    name: Chat
  - description: OpenAI Responses API compatible endpoint
    name: Responses
  - description: Google-compatible interactions endpoint
    name: Interactions
  - description: Model registry and capabilities
    name: Models
  - description: Synchronous image generation
    name: Images
  - description: Text-to-speech and speech-to-text
    name: Audio
  - description: Asynchronous video generation
    name: Videos
  - description: Reusable file storage for media inputs and generated outputs
    name: Files
  - description: Async generation status and downloads
    name: Artifacts
  - description: OpenAI-compatible embeddings
    name: Embeddings
  - description: Recorded HTTP request/response generations
    name: Generations
  - description: System health and status
    name: System
  - description: Roundtable endpoint — fan out a query to multiple LLMs and combine results
    name: Roundtable
  - description: Web search, fetch, and other utility tools
    name: Tools
paths:
  /v3/compat/v1/messages/count_tokens:
    post:
      tags:
        - Compatibility
      summary: Count Message tokens
      description: >-
        Anthropic Messages token-counting compatible endpoint. Returns the
        number of input tokens a Messages request would consume, without
        creating a message. Mirrors Anthropic's POST /v1/messages/count_tokens
        (same request body as the Messages endpoint, minus the required
        max_tokens). Supported for Claude models; other models return 400.
      operationId: countMessageTokens
      parameters:
        - description: >-
            Function name for tracing and project-level guardrail function-scope
            filtering.
          in: header
          name: X-Opper-Name
          schema:
            type: string
        - description: Parent span ID for distributed tracing context.
          in: header
          name: X-Opper-Parent-Span-Id
          schema:
            format: uuid
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessagesRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  input_tokens:
                    description: The number of input tokens the request would consume.
                    type: integer
                required:
                  - input_tokens
                type: object
          description: Successful response
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Bad request
        '401':
          description: Unauthorized - missing or invalid API key
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal server error
components:
  schemas:
    MessagesRequest:
      properties:
        max_tokens:
          type: integer
        messages:
          items:
            properties:
              content:
                description: Any value
              role:
                type: string
            required:
              - role
              - content
            type: object
          type: array
        model:
          type: string
        output_format:
          type: object
        stop_sequences:
          items:
            type: string
          type: array
        stream:
          type: boolean
        system:
          description: Any value
        temperature:
          type: number
        thinking:
          description: Any value
        tool_choice:
          description: Any value
        tools:
          items:
            properties:
              cache_control:
                type: object
              description:
                type: string
              input_schema:
                type: object
              name:
                type: string
              type:
                type: string
            required:
              - name
            type: object
          type: array
        top_k:
          type: integer
        top_p:
          type: number
      required:
        - model
        - messages
        - max_tokens
      type: object
    ErrorResponse:
      properties:
        error:
          properties:
            code:
              type: string
            details:
              description: Any value
            message:
              type: string
          required:
            - code
            - message
          type: object
        meta:
          type: object
      required:
        - error
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: API Key
      description: API key authentication. Pass your API key as a Bearer token.
      scheme: bearer
      type: http

````