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

# Anthropic Messages Count Tokens

`POST /anthropic/v1/messages/count_tokens`

## Request

- Base URL: `https://api.deepinfra.com`
- URL: `https://api.deepinfra.com/anthropic/v1/messages/count_tokens`
- Auth: HTTP bearer

## Headers

- `x-deepinfra-service-tier` string, nullable: Per-request service tier (`priority` or `flex`) for clients that cannot set the `service_tier` body field. The body field wins when both are present; unrecognized values ride the default tier.
- `xi-api-key` string, nullable
- `x-api-key` string, nullable

## Request body

- AnthropicTokenCountRequest
  - `model` string, required
  - `messages` object[], required
  - `system` union
    - string
    - AnthropicSystemContent[]
      - `type` 'text', required
      - `text` string, required
  - `tools` AnthropicTool[], nullable
    - `name` string, required
    - `description` string, nullable
    - `input_schema` object, required
  - `thinking` AnthropicThinkingConfig: Anthropic `thinking` config: {type: enabled|disabled|adaptive, budget_tokens}. `enabled` is a legacy pre-spec field this endpoint used to accept; it only applies when `type` is absent.
    - `type` 'enabled' | 'disabled' | 'adaptive', nullable
    - `budget_tokens` integer, nullable
    - `enabled` boolean, nullable
  - `tool_choice` object, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

## Changes

- **2026-09-10** `f1c865cab90d`: 1 info
  - added the new optional `header` request parameter `x-deepinfra-service-tier`
- **2026-08-07** `2df28210837a`: 4 info
  - added the new optional request property `thinking/anyOf[subschema #1: AnthropicThinkingConfig]/budget_tokens`
  - added the new optional request property `thinking/anyOf[subschema #1: AnthropicThinkingConfig]/type`
  - the `enabled` request property default value `true` was removed
  - request property `thinking/anyOf[subschema #1: AnthropicThinkingConfig]/enabled` list-of-types was widened by adding types `null` to media type `application/json`
- **2026-07-13** `610da191cbe7`: 1 warning, 3 info
  - deleted the `header` request parameter `authorization`
  - the endpoint scheme security `HTTPBearer` was added to the API
  - api tag `Chat Completions` added
  - added the new optional `header` request parameter `xi-api-key`

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

---

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