---
title: "Count Tokens"
method: POST
path: "/messages/count_tokens"
---

# Count Tokens

`POST /messages/count_tokens`

## Request

- Base URL: `https://api.electronhub.ai/v1`
- URL: `https://api.electronhub.ai/v1/messages/count_tokens`
- Auth: HTTP bearer

Estimate input tokens for a Messages-shaped request body. Returns input_tokens without running inference.

## Request body

- MessageRequest
  - `model` string, required: Model ID
  - `messages` AnthropicMessage[], required: Conversation turns
    - `role` 'user' | 'assistant' | 'system', required: Turn role. Mid-conversation system turns are accepted.
    - `content` union, required
      - string
      - AnthropicContentPart[]
        - union
          - AnthropicTextContent
            - `type` 'text', required
            - `text` string, required
          - AnthropicImageContent
            - `type` 'image', required
            - `source` AnthropicImageSource, required
              - …
          - AnthropicToolUseContent
            - `type` 'tool_use', required
            - `id` string, required
            - `name` string, required
            - `input` object, required
          - AnthropicToolResultContent
            - `type` 'tool_result', required
            - `tool_use_id` string, required
            - `content` union
              - …
            - `is_error` boolean
          - AnthropicThinkingContent
            - `type` 'thinking', required
            - `thinking` string, required
            - `signature` string
          - AnthropicRedactedThinkingContent
            - `type` 'redacted_thinking', required
            - `data` string
  - `max_tokens` integer: Maximum tokens to generate
  - `temperature` number
  - `top_p` number
  - `top_k` integer
  - `stream` boolean
  - `system` union
    - string
    - object[]
      - `type` 'text'
      - `text` string
      - `cache_control` object
  - `tools` AnthropicTool[]
    - `name` string, required
    - `description` string
    - `input_schema` object
    - `type` string: Built-in Anthropic tool type when applicable
    - `strict` boolean
    - `defer_loading` boolean
    - `eager_input_streaming` boolean
  - `tool_choice` union
    - 'auto' | 'any' | 'none'
    - object
      - `type` 'auto' | 'any' | 'none' | 'tool', required
      - `name` string: Required when type is tool
  - `thinking` union
    - object
      - `type` 'enabled', required
      - `budget_tokens` integer, required: Token budget for thinking
      - `display` 'summarized' | 'omitted'
    - object
      - `type` 'adaptive' | 'disabled', required
      - `display` 'summarized' | 'omitted'
  - `reasoning_effort` 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh': Ignored for models that do not support reasoning_effort
  - `betas` string[]
  - `context_management` object
  - `output_config` object
  - `metadata` object

## Response `200`

Success

- CountTokensResponse
  - `input_tokens` integer, required

## Changes

- **2026-11-03** `a4ddf2e02571`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/electronhub/apis/electron-hub-api/changes/messages/count_tokens/post.md)

---

[API](https://skmtc.dev/electronhub/apis/electron-hub-api.md) - [All operations](https://skmtc.dev/electronhub/apis/electron-hub-api/llms.txt) - [OpenAPI document](https://skmtc.dev/electronhub/apis/electron-hub-api/revisions/a4ddf2e02571?raw)
