---
title: "Anthropic Count Tokens"
method: POST
path: "/v1/messages/count_tokens"
tags: ["Anthropic Messages"]
---

# Anthropic Count Tokens

`POST /v1/messages/count_tokens`

## Request

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

## Headers

- `x-api-key` string

## Request body

- CountTokensRequest
  - `model` string, required
  - `messages` MessageInput[], required
    - `role` 'user' | 'assistant', required
    - `content` union, required
      - string
      - union[]
        - union
          - TextBlock
            - `type` 'text'
            - `text` string, required
            - `cache_control` object, nullable
          - ImageBlock
            - `type` 'image'
            - `source` ImageSource, required
              - …
          - DocumentBlock
            - `type` 'document'
            - `source` DocumentSource, required
              - …
          - ToolUseBlock
            - `type` 'tool_use'
            - `id` string, required
            - `name` string, required
            - `input` object, required
          - ToolResultBlock
            - `type` 'tool_result'
            - `tool_use_id` string, required
            - `content` union, required
              - …
            - `is_error` boolean, nullable
  - `system` union
    - string
    - union[]
      - union
        - TextBlock
          - `type` 'text'
          - `text` string, required
          - `cache_control` object, nullable
        - ImageBlock
          - `type` 'image'
          - `source` ImageSource, required
            - `type` 'base64' | 'url', required
            - `media_type` 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp', required
            - `data` string, nullable
            - `url` string, nullable
        - DocumentBlock
          - `type` 'document'
          - `source` DocumentSource, required
            - `type` 'base64' | 'url', required
            - `media_type` 'application/pdf', required
            - `data` string, nullable
            - `url` string, nullable
        - ToolUseBlock
          - `type` 'tool_use'
          - `id` string, required
          - `name` string, required
          - `input` object, required
        - ToolResultBlock
          - `type` 'tool_result'
          - `tool_use_id` string, required
          - `content` union, required
            - string
            - object[]
              - …
          - `is_error` boolean, nullable
  - `tools` ToolDefinition[], nullable
    - `name` string, required
    - `description` string, required
    - `input_schema` ToolInputSchema, required
      - `type` 'object'
      - `properties` object, required
      - `required` string[]
    - `input_examples` object[], nullable
    - `cache_control` object, nullable
    - `strict` boolean, nullable
    - `defer_loading` boolean, nullable
    - `allowed_callers` string[], nullable
  - `thinking` union
    - ThinkingConfigEnabled
      - `type` 'enabled'
      - `budget_tokens` integer, required
    - ThinkingConfigDisabled
      - `type` 'disabled'
    - ThinkingConfigAdaptive
      - `type` 'adaptive'
      - `budget_tokens` integer, nullable
  - `metadata` object, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

## Changes

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

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

---

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