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

# Count message tokens

> Estimate input tokens for a Messages request. Same body as /v1/messages. Free: nothing is billed and no model runs.



## OpenAPI

````yaml /openapi.json post /v1/messages/count_tokens
openapi: 3.1.0
info:
  title: Refuseless API
  version: 1.0.0
  description: >-
    OpenAI-compatible hosted inference for a named lineup of refusal-removed
    open weights.
servers:
  - url: https://api.refuseless.com
security:
  - bearerAuth: []
paths:
  /v1/messages/count_tokens:
    post:
      tags:
        - Completions
      summary: Count message tokens
      description: >-
        Estimate input tokens for a Messages request. Same body as /v1/messages.
        Free: nothing is billed and no model runs.
      operationId: countMessageTokens
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessagesRequest'
            example:
              model: glm-5.3-abliterated
              max_tokens: 512
              messages:
                - role: user
                  content: Write a tight system prompt.
      responses:
        '200':
          description: Token estimate
          content:
            application/json:
              schema:
                type: object
                properties:
                  input_tokens:
                    type: integer
        '400':
          description: Missing model or invalid messages
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnthropicError'
components:
  schemas:
    MessagesRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: glm-5.3-abliterated
        messages:
          type: array
          items:
            $ref: '#/components/schemas/AnthropicMessage'
        system:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        max_tokens:
          type: integer
          description: Output limit. Defaults to the model's max output.
        stream:
          type: boolean
          default: false
        temperature:
          type: number
        top_p:
          type: number
        top_k:
          type: integer
        stop_sequences:
          type: array
          items:
            type: string
          maxItems: 4
        tools:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              description:
                type: string
              input_schema:
                type: object
                additionalProperties: true
        tool_choice:
          type: object
          additionalProperties: true
        thinking:
          type: object
          properties:
            type:
              type: string
              enum:
                - enabled
                - disabled
                - adaptive
            budget_tokens:
              type: integer
        output_config:
          type: object
          properties:
            effort:
              type: string
              enum:
                - low
                - medium
                - high
                - xhigh
                - max
        reasoning_effort:
          type: string
          enum:
            - 'off'
            - low
            - high
            - max
    AnthropicError:
      type: object
      properties:
        type:
          type: string
          example: error
        error:
          type: object
          properties:
            type:
              type: string
              example: invalid_request_error
            message:
              type: string
    AnthropicMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
          description: >-
            String, or an array of text, image, document, tool_use, or
            tool_result blocks.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      x-default: YOUR_API_KEY

````

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