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

# Count Anthropic Tokens

`POST /v3/v1/messages/count_tokens`

## Request

- Base URL: `https://api.edenai.run`
- URL: `https://api.edenai.run/v3/v1/messages/count_tokens`
- Auth: HTTP bearer

Count input tokens for an Anthropic-format request without running the model.

## Request body

- AnthropicCountTokensBody: Body for /v1/messages/count_tokens, same fields as messages but max_tokens is optional. Not a pass-through body: ``count_tokens_for_request`` runs litellm's tokenizer locally and never builds a provider call, so there is nothing for an unknown field to reach. Unknown fields are dropped rather than refused, which also keeps ``tags`` working here: this body does not inherit ``TagsBody``, and litellm happens to reserve that name.
  - `model` string, required
  - `messages` AnthropicMessage[], required
    - `role` 'user' | 'assistant' | 'system', required
    - `content` union, required
      - string
      - AnthropicContentBlock[]
        - `type` string, required
        - `text` string, nullable
        - `id` string, nullable
        - `name` string, nullable
        - `input` object, nullable
        - `tool_use_id` string, nullable
        - `content` union
          - string
          - unknown[]
            - unknown
        - `is_error` boolean, nullable
        - `source` object, nullable
        - `thinking` string, nullable
        - `signature` string, nullable
    - `cache_control` CacheControl: Prompt-cache marker. Marks a message (or content part) as a cache boundary so that the prefix up to that point is stored and reused on subsequent requests, reducing latency and cost. Only a single contiguous cache-marked block is stored per request, and providers enforce a minimum token count below which caching is silently skipped. Silently ignored by providers that don't support prompt caching.
      - `type` 'ephemeral', required: Cache type. Currently only 'ephemeral' is supported.
      - `ttl` string, nullable: Optional cache time-to-live, e.g. '3600s'. Provider-dependent.
  - `system` union
    - string
    - object[]
  - `tools` object[], nullable
  - `tool_choice` object, nullable

## Response `200`

Successful Response

- AnthropicCountTokensResponse: Response body for POST /v1/messages/count_tokens.
  - `input_tokens` integer, required: Number of input tokens the request would consume.

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/edenai/apis/eden-ai-api-v3.md) - [All operations](https://skmtc.dev/edenai/apis/eden-ai-api-v3/llms.txt) - [OpenAPI document](https://skmtc.dev/edenai/apis/eden-ai-api-v3/revisions/20ddfd49a3f4?raw)
