> ## Documentation Index
> Fetch the complete documentation index at: https://gomodel-docs-benchmark-writeup-and-tooling.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Count message tokens (Anthropic Messages API)

> Returns a provider-agnostic heuristic estimate of the input token count.



## 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, OpenRouter, 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: Returns a provider-agnostic heuristic estimate of the input token count.
      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:
        max_tokens:
          type: integer
        messages:
          type: array
          items:
            $ref: '#/components/schemas/anthropicapi.Message'
        metadata:
          $ref: '#/components/schemas/anthropicapi.Metadata'
        model:
          type: string
        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
        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.ContentBlock:
      type: object
      properties:
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/anthropicapi.ContentBlock'
        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
        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:
        description:
          type: string
        input_schema:
          type: object
          additionalProperties: true
        name:
          type: string
        type:
          type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````