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

# Count message tokens (Anthropic Messages API)

> GoModel API reference for POST /v1/messages/count_tokens: Count message tokens (Anthropic Messages API).



## OpenAPI

````yaml /openapi.json post /v1/messages/count_tokens
openapi: 3.0.0
info:
  description: >-
    AI gateway routing requests to multiple LLM providers (OpenAI, Anthropic,
    Gemini, Groq, Fireworks AI, Meta, OpenRouter, Kilo AI, DeepSeek, Z.ai, xAI,
    MiniMax, Xiaomi MiMo, OpenCode Go, Oracle, Ollama, Bailian). Drop-in
    OpenAI-compatible API.
  title: GoModel API
  contact: {}
  version: '1.0'
servers:
  - url: '{base_url}'
    description: Edit the base URL to point at your GoModel deployment.
    variables:
      base_url:
        default: http://localhost:8080
        description: Your GoModel deployment URL
security: []
paths:
  /v1/messages/count_tokens:
    post:
      tags:
        - messages
      summary: Count message tokens (Anthropic Messages API)
      description: >-
        Counts the input tokens of a Messages request. Exact when the provider
        that owns the model has a token counting endpoint (Anthropic); otherwise
        a calibrated estimate.
      requestBody:
        $ref: '#/components/requestBodies/anthropicapi.MessagesRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/anthropicapi.CountTokensResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/anthropicapi.ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/anthropicapi.ErrorResponse'
      security:
        - BearerAuth: []
components:
  requestBodies:
    anthropicapi.MessagesRequest:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/anthropicapi.MessagesRequest'
      description: Anthropic Messages request
      required: true
  schemas:
    anthropicapi.CountTokensResponse:
      type: object
      properties:
        input_tokens:
          type: integer
    anthropicapi.ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/anthropicapi.ErrorObject'
        type:
          type: string
    anthropicapi.MessagesRequest:
      type: object
      properties:
        cache_control:
          type: object
        max_tokens:
          type: integer
        messages:
          type: array
          items:
            $ref: '#/components/schemas/anthropicapi.Message'
        metadata:
          $ref: '#/components/schemas/anthropicapi.Metadata'
        model:
          type: string
        output_config:
          description: >-
            OutputConfig carries structured output (format) and the effort
            level.
          allOf:
            - $ref: '#/components/schemas/anthropicapi.OutputConfig'
        output_format:
          description: >-
            OutputFormat is the deprecated top-level form of
            output_config.format.
          type: object
        stop_sequences:
          type: array
          items:
            type: string
        stream:
          type: boolean
        system:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/anthropicapi.ContentBlock'
        temperature:
          type: number
        thinking:
          $ref: '#/components/schemas/anthropicapi.Thinking'
        tool_choice:
          $ref: '#/components/schemas/anthropicapi.ToolChoice'
        tools:
          type: array
          items:
            $ref: '#/components/schemas/anthropicapi.Tool'
        top_k:
          type: integer
        top_p:
          type: number
    anthropicapi.ErrorObject:
      type: object
      properties:
        message:
          type: string
        provider:
          description: |-
            Provider names the upstream provider that produced the error. It is
            omitted for errors raised by the gateway itself.
          type: string
        type:
          type: string
    anthropicapi.Message:
      type: object
      properties:
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/anthropicapi.ContentBlock'
        role:
          type: string
    anthropicapi.Metadata:
      type: object
      properties:
        user_id:
          type: string
    anthropicapi.OutputConfig:
      type: object
      properties:
        effort:
          type: string
        format:
          type: object
    anthropicapi.ContentBlock:
      type: object
      properties:
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/anthropicapi.ContentBlock'
        extra_content:
          type: object
          additionalProperties: true
        id:
          type: string
        input:
          type: object
          additionalProperties: true
        is_error:
          type: boolean
        name:
          type: string
        source:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
        text:
          type: string
        thinking:
          type: string
        signature:
          type: string
        data:
          type: string
        tool_use_id:
          type: string
        type:
          type: string
    anthropicapi.Thinking:
      type: object
      properties:
        budget_tokens:
          type: integer
        type:
          type: string
    anthropicapi.ToolChoice:
      type: object
      properties:
        disable_parallel_tool_use:
          type: boolean
        name:
          type: string
        type:
          type: string
    anthropicapi.Tool:
      type: object
      properties:
        cache_control:
          type: object
        defer_loading:
          description: >-
            DeferLoading marks a tool whose schema the API loads only when tool

            search matches it. It is an ordinary custom tool that declares
            itself

            deferred, so the translated pipeline sends it like any other and
            drops

            the marker (see convertTools).
          type: boolean
        description:
          type: string
        input_schema:
          type: object
          additionalProperties: true
        name:
          type: string
        strict:
          type: boolean
        type:
          type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````

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