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

# Count Anthropic message tokens

> Count the input tokens for a native Anthropic Messages request without creating a model response. The model uses the same project-scoped provider credential and access policy as `/v1/messages`. Native token-count support is required for the selected provider and model; Aixy does not synthesize it from translated conversation support.



## OpenAPI

````yaml /openapi.json post /v1/messages/count_tokens
openapi: 3.1.0
info:
  title: Aixy Inference API
  version: 0.1.0
  description: >-
    Route requests to configured AI providers through OpenAI- and
    Anthropic-compatible APIs. Aixy applies project access, model policies,
    guardrails, routing, budgets, and usage attribution before forwarding
    inference traffic. Create connections, API keys and policies in the Aixy
    dashboard. The management API is a dashboard service and is not a public
    integration contract. Native provider features depend on the selected model
    and connection; translated requests support the documented conversation and
    function-tool subset. Unsupported combinations return explicit errors.
    Examples use illustrative model IDs; select an ID available to your project.
servers:
  - url: https://api.aixy-gateway.com
    description: Aixy production gateway
security: []
tags:
  - name: OpenAI
    description: OpenAI-compatible conversations, function tools and incremental streams.
  - name: Anthropic
    description: Anthropic-compatible messages and provider-native input token counting.
  - name: Decisions
    description: Typed, non-streaming classification and scoring inference.
  - name: Models
    description: Discover the models available to your project API key.
paths:
  /v1/messages/count_tokens:
    post:
      tags:
        - Anthropic
      summary: Count Anthropic message tokens
      description: >-
        Count the input tokens for a native Anthropic Messages request without
        creating a model response. The model uses the same project-scoped
        provider credential and access policy as `/v1/messages`. Native
        token-count support is required for the selected provider and model;
        Aixy does not synthesize it from translated conversation support.
      operationId: count_message_tokens
      parameters:
        - $ref: '#/components/parameters/XRequestId'
        - $ref: '#/components/parameters/XAixyClient'
        - $ref: '#/components/parameters/XAixySession'
        - $ref: '#/components/parameters/XAixySessionId'
        - $ref: '#/components/parameters/AnthropicVersion'
        - $ref: '#/components/parameters/AnthropicBeta'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnthropicTokenCountRequest'
            examples:
              basic:
                summary: Basic request
                value:
                  model: anthropic/claude-sonnet-4-5
                  messages:
                    - role: user
                      content: Explain this code.
              functionTools:
                summary: Function tools (executed by your application)
                value:
                  model: anthropic/claude-sonnet-4-5
                  messages:
                    - role: user
                      content: What is the weather in Paris?
                  tools:
                    - name: get_weather
                      description: Read the weather for a city.
                      input_schema:
                        type: object
                        properties:
                          city:
                            type: string
                        required:
                          - city
                        additionalProperties: false
      responses:
        '200':
          description: Successful Anthropic response.
          headers:
            x-request-id:
              description: >-
                Aixy request identifier for correlation with Activity and
                support.
              schema:
                type: string
              example: req_example_01
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicTokenCount'
              example:
                input_tokens: 8
        '400':
          $ref: '#/components/responses/AnthropicError'
        '401':
          $ref: '#/components/responses/AnthropicError'
        '403':
          $ref: '#/components/responses/AnthropicError'
        '404':
          $ref: '#/components/responses/AnthropicError'
        '408':
          $ref: '#/components/responses/AnthropicError'
        '413':
          $ref: '#/components/responses/AnthropicError'
        '424':
          $ref: '#/components/responses/AnthropicError'
        '429':
          $ref: '#/components/responses/AnthropicRateLimitError'
        '500':
          $ref: '#/components/responses/InferenceInternalError'
        '502':
          $ref: '#/components/responses/AnthropicError'
        '503':
          $ref: '#/components/responses/AnthropicError'
        '504':
          $ref: '#/components/responses/AnthropicError'
        default:
          $ref: '#/components/responses/NativeProviderError'
      security:
        - GatewayApiKey: []
        - AnthropicApiKey: []
components:
  parameters:
    XRequestId:
      name: X-Request-ID
      in: header
      required: false
      description: Optional caller-generated request identifier for end-to-end tracing.
      schema:
        type: string
        maxLength: 255
    XAixyClient:
      name: X-Aixy-Client
      in: header
      required: false
      description: >-
        Optional application[/version] for Activity attribution. Overrides
        User-Agent detection. Use a product name, not personal data or
        credentials. Names are 1-64 ASCII letters, digits, spaces, dots,
        underscores or hyphens, starting with a letter or digit. Optional
        versions start with a digit and use up to 32 letters, digits, dots,
        underscores, plus signs or hyphens. Invalid values are ignored. This
        self-declared label grants no permissions and is not forwarded.
      schema:
        type: string
        maxLength: 97
        example: Acme Support/1.2.3
    XAixySession:
      name: X-Aixy-Session
      in: header
      required: false
      description: >-
        Optional opaque session identifier for virtual routes with session
        affinity. Scoped to the authenticated caller and alias; never forwarded
        or recorded. Send full conversation history. Invalid values return 400
        when affinity is enabled. Omission retains the route's normal strategy.
      schema:
        type: string
        minLength: 1
        maxLength: 128
        pattern: ^[A-Za-z0-9._:-]+$
        example: conversation-82
    XAixySessionId:
      name: X-Aixy-Session-ID
      in: header
      required: false
      description: >-
        Optional opaque conversation identifier recorded in Activity metadata.
        Reuse it for every call in a conversation. Sessions are isolated by
        organization, project, user and API key. Use no personal data or
        secrets. Invalid values are ignored. The header is not forwarded, grants
        no permissions and does not change routing affinity.
      schema:
        type: string
        minLength: 1
        maxLength: 128
        pattern: ^[A-Za-z0-9._:-]+$
        example: conversation-82
    AnthropicVersion:
      name: anthropic-version
      in: header
      required: true
      description: >-
        Anthropic client contract version; forwarded unchanged on native
        requests. Reviewed Bedrock InvokeModel routes use the required upstream
        envelope version.
      schema:
        type: string
        example: '2023-06-01'
    AnthropicBeta:
      name: anthropic-beta
      in: header
      required: false
      description: >-
        Comma-separated Anthropic beta features, forwarded on matching native
        requests. Reviewed destination compatibility rules may omit unused beta
        announcements; unsupported features in use fail explicitly. Repeated
        headers are additive. Preserved Bedrock InvokeModel routes carry beta
        features in the upstream envelope. Translated routes reject unsupported
        beta features.
      schema:
        type: string
  schemas:
    AnthropicTokenCountRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: >-
            Provider-qualified or routing model with a supported native token
            counter.
          example: anthropic/claude-sonnet-4-5
        messages:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicMessageParam'
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        tools:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicTool'
      additionalProperties: true
    AnthropicTokenCount:
      type: object
      required:
        - input_tokens
      properties:
        input_tokens:
          type: integer
          minimum: 0
      additionalProperties: true
    AnthropicMessageParam:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/AnthropicContentBlock'
      additionalProperties: true
    AnthropicTool:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        description:
          type: string
        input_schema:
          type: object
          additionalProperties: true
          description: JSON Schema for a client function tool's arguments.
        type:
          type: string
          description: Server tools require compatible native provider support.
        cache_control:
          type: object
          additionalProperties: true
      additionalProperties: true
    AnthropicErrorResponse:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          enum:
            - error
        error:
          type: object
          required:
            - type
            - message
          properties:
            type:
              type: string
            message:
              type: string
          additionalProperties: true
        request_id:
          type: string
      additionalProperties: true
    InferenceErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
          properties:
            message:
              type: string
            code:
              type:
                - string
                - 'null'
            type:
              type:
                - string
                - 'null'
            param:
              type:
                - string
                - integer
                - 'null'
            details:
              type:
                - object
                - 'null'
              additionalProperties: true
          additionalProperties: true
        type:
          type: string
        request_id:
          type: string
      additionalProperties: true
    AnthropicContentBlock:
      type: object
      required:
        - type
      description: >-
        Typed text, image, document, tool_use or tool_result content. Thinking,
        signed reasoning, caching and other provider blocks require compatible
        native support; additional fields are not a promise of translation
        support.
      properties:
        type:
          type: string
          example: text
        text:
          type: string
        source:
          type: object
          additionalProperties: true
          description: >-
            Provider image/document source, including compatible URL or base64
            input.
        id:
          type: string
          description: Identifier of a tool_use block.
        name:
          type: string
          description: Function tool name.
        input:
          type: object
          additionalProperties: true
        tool_use_id:
          type: string
          description: Matching tool_use identifier for a tool_result.
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        is_error:
          type: boolean
        thinking:
          type: string
        signature:
          type: string
        cache_control:
          type: object
          additionalProperties: true
          description: >-
            Native provider prompt-cache marker; support depends on the
            destination.
      additionalProperties: true
  responses:
    AnthropicError:
      description: The gateway or Anthropic-compatible provider rejected the request.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthropicErrorResponse'
          example:
            type: error
            error:
              type: authentication_error
              message: Gateway API key is invalid or revoked
            request_id: req_01H...
    AnthropicRateLimitError:
      description: Aixy or the Anthropic-compatible provider rate limited the request.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
        Retry-After:
          description: >-
            Optional retry delay. Aixy rate-limit rejections provide a positive
            delay in seconds; a provider may supply its own Retry-After value,
            including an HTTP date.
          required: false
          schema:
            type: string
          example: '60'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AnthropicErrorResponse'
          example:
            type: error
            error:
              type: rate_limit_error
              message: The configured rate limit was reached. Retry later.
            request_id: req_01H...
    InferenceInternalError:
      description: >-
        An internal failure occurred. Some failures return a generic text
        response; record x-request-id and avoid relying on a JSON body for every
        server error.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
      content:
        text/plain:
          schema:
            type: string
          example: Internal Server Error
        application/json:
          schema:
            anyOf:
              - $ref: '#/components/schemas/InferenceErrorResponse'
              - $ref: '#/components/schemas/AnthropicErrorResponse'
    NativeProviderError:
      description: >-
        A native provider may return another error status and its original
        payload. After streaming starts, failures can arrive inside the SSE
        stream instead of changing the HTTP status. Handle both HTTP errors and
        protocol error events.
      headers:
        x-request-id:
          description: Aixy request identifier for correlation with Activity and support.
          schema:
            type: string
          example: req_example_01
      content:
        application/json:
          schema:
            type: object
            additionalProperties: true
  securitySchemes:
    GatewayApiKey:
      type: http
      scheme: bearer
      bearerFormat: gak_…
      description: >-
        A project-scoped Aixy API key. Create keys in the dashboard and send the
        secret as a Bearer token.
    AnthropicApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        A project-scoped Aixy `gak_` key sent using the Anthropic authentication
        header. This is equivalent to `Authorization: Bearer` and is supported
        for Claude Code and Anthropic SDK compatibility.

````

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