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

# Count tokens



## OpenAPI

````yaml POST /v1/messages/count_tokens
openapi: 3.1.0
info:
  title: Antara API
  version: 1.0.0
  description: OpenAI- and Anthropic-compatible inference plus organization management.
servers:
  - url: https://api.antarah.dev
security: []
paths:
  /v1/messages/count_tokens:
    post:
      summary: >-
        Count a Messages request's input tokens (cached 10 min by body; not
        billed; counts toward RPM only)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CountTokensRequest'
      responses:
        '200':
          description: OK
          headers:
            x-request-id:
              schema:
                type: string
                description: Request ID (`req_…`); also sent as `request-id`
              required: false
              description: Request ID (`req_…`); also sent as `request-id`
            ratelimit-policy:
              schema:
                type: string
                description: e.g. `"rpm";q=60;w=60` (02 §8)
              required: false
              description: e.g. `"rpm";q=60;w=60` (02 §8)
            ratelimit:
              schema:
                type: string
                description: Scope closest to exhaustion, e.g. `"rpm";r=59;t=42`
              required: false
              description: Scope closest to exhaustion, e.g. `"rpm";r=59;t=42`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CountTokens'
        '404':
          description: '`model_not_found`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '502':
          description: '`upstream_error`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '503':
          description: '`upstream_unavailable`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '504':
          description: '`upstream_timeout`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        default:
          description: Anthropic-shaped error (02 §4.1)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
      security:
        - projectKey: []
        - session: []
components:
  schemas:
    CountTokensRequest:
      type: object
      properties:
        model:
          type: string
          minLength: 1
          description: Public model ID, e.g. `a1` (A-05)
          example: a1
        messages:
          type: array
          items:
            oneOf:
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - user
                  content:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          oneOf:
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                text:
                                  type: string
                                  minLength: 1
                              required:
                                - type
                                - text
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - image
                                source:
                                  oneOf:
                                    - type: object
                                      properties:
                                        type:
                                          type: string
                                          enum:
                                            - base64
                                        media_type:
                                          type: string
                                          enum:
                                            - image/png
                                            - image/jpeg
                                            - image/webp
                                            - image/gif
                                        data:
                                          type: string
                                      required:
                                        - type
                                        - media_type
                                        - data
                                    - type: object
                                      properties:
                                        type:
                                          type: string
                                          enum:
                                            - url
                                        url:
                                          type: string
                                      required:
                                        - type
                                        - url
                              required:
                                - type
                                - source
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - tool_result
                                tool_use_id:
                                  type: string
                                  minLength: 1
                                content:
                                  anyOf:
                                    - type: string
                                    - type: array
                                      items:
                                        oneOf:
                                          - type: object
                                            properties:
                                              type:
                                                type: string
                                                enum:
                                                  - text
                                              text:
                                                type: string
                                                minLength: 1
                                            required:
                                              - type
                                              - text
                                          - type: object
                                            properties:
                                              type:
                                                type: string
                                                enum:
                                                  - image
                                              source:
                                                oneOf:
                                                  - type: object
                                                    properties:
                                                      type:
                                                        type: string
                                                        enum:
                                                          - base64
                                                      media_type:
                                                        type: string
                                                        enum:
                                                          - image/png
                                                          - image/jpeg
                                                          - image/webp
                                                          - image/gif
                                                      data:
                                                        type: string
                                                    required:
                                                      - type
                                                      - media_type
                                                      - data
                                                  - type: object
                                                    properties:
                                                      type:
                                                        type: string
                                                        enum:
                                                          - url
                                                      url:
                                                        type: string
                                                    required:
                                                      - type
                                                      - url
                                            required:
                                              - type
                                              - source
                                is_error:
                                  type: boolean
                              required:
                                - type
                                - tool_use_id
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - document
                              required:
                                - type
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - search_result
                              required:
                                - type
                        minItems: 1
                required:
                  - role
                  - content
              - type: object
                properties:
                  role:
                    type: string
                    enum:
                      - assistant
                  content:
                    anyOf:
                      - type: string
                      - type: array
                        items:
                          oneOf:
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                text:
                                  type: string
                                  minLength: 1
                              required:
                                - type
                                - text
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - tool_use
                                id:
                                  type: string
                                  minLength: 1
                                name:
                                  type: string
                                  minLength: 1
                                input:
                                  type: object
                                  additionalProperties: {}
                              required:
                                - type
                                - id
                                - name
                                - input
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - thinking
                                thinking:
                                  type: string
                                signature:
                                  type: string
                              required:
                                - type
                                - thinking
                            - type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - redacted_thinking
                                data:
                                  type: string
                              required:
                                - type
                                - data
                required:
                  - role
                  - content
          minItems: 1
          maxItems: 10000
        system:
          anyOf:
            - type: string
            - type: array
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
                    minLength: 1
                required:
                  - type
                  - text
        tools:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              name:
                type: string
                minLength: 1
              description:
                type: string
              input_schema:
                type: object
                additionalProperties: {}
            required:
              - name
          maxItems: 128
        tool_choice:
          oneOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - auto
                disable_parallel_tool_use:
                  type: boolean
              required:
                - type
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - any
                disable_parallel_tool_use:
                  type: boolean
              required:
                - type
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - none
              required:
                - type
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - tool
                name:
                  type: string
                  minLength: 1
                disable_parallel_tool_use:
                  type: boolean
              required:
                - type
                - name
        thinking:
          anyOf:
            - type: boolean
              enum:
                - false
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - enabled
                budget_tokens:
                  type: integer
                  minimum: 1
              required:
                - type
                - budget_tokens
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - disabled
              required:
                - type
      required:
        - model
        - messages
      additionalProperties: false
    CountTokens:
      type: object
      properties:
        input_tokens:
          type: integer
      required:
        - input_tokens
    AnthropicError:
      type: object
      properties:
        type:
          type: string
          enum:
            - error
        error:
          type: object
          properties:
            type:
              type: string
              example: invalid_request_error
            message:
              type: string
            code:
              type: string
          required:
            - type
            - message
            - code
        request_id:
          type: string
      required:
        - type
        - error
        - request_id
  securitySchemes:
    projectKey:
      type: http
      scheme: bearer
      description: '`ak_…` project API key (or `x-api-key`)'
    session:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Supabase access token + `Antara-Organization` (management) or
        `Antara-Project` (inference)

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.